Upgrade eslint to v6 and add TypeScript linting (#3843)

* Upgrade eslint to v6 and add TypeScript linting

* Fix pr checks


Co-authored-by: Benjamin Staneck <Stanzilla@users.noreply.github.com>
This commit is contained in:
Labhansh Agrawal 2019-10-03 06:26:50 +05:30 committed by Benjamin Staneck
parent 25fc964ae8
commit b52d8152bf
18 changed files with 616 additions and 271 deletions

View file

@ -1,12 +1,12 @@
sudo: required
dist: trusty
dist: xenial
language: node_js
matrix:
include:
- os: linux
node_js: 10.2.0
node_js: 12.10.0
env: CC=clang CXX=clang++ npm_config_clang=1
compiler: clang

View file

@ -14,7 +14,9 @@ const homeDirectory = homedir();
const applicationDirectory =
process.env.XDG_CONFIG_HOME !== undefined
? join(process.env.XDG_CONFIG_HOME, 'hyper')
: process.platform == 'win32' ? app.getPath('userData') : homedir();
: process.platform == 'win32'
? app.getPath('userData')
: homedir();
let cfgDir = applicationDirectory;
let cfgPath = join(applicationDirectory, cfgFile);

View file

@ -8,7 +8,6 @@ if (['--help', '-v', '--version'].includes(process.argv[1])) {
console.log('Hyper does not accept any command line arguments. Please modify the config file instead.');
//eslint-disable-next-line no-console
console.log(`Hyper configuration file located at: ${configLocation}`);
// eslint-disable-next-line unicorn/no-process-exit
process.exit();
}
@ -20,14 +19,12 @@ const checkSquirrel = () => {
//eslint-disable-next-line no-empty
} catch (err) {}
if (squirrel) {
// eslint-disable-next-line unicorn/no-process-exit
process.exit();
}
};
// handle startup squirrel events
if (process.platform === 'win32') {
// eslint-disable-next-line import/order
const systemContextMenu = require('./system-context-menu');
switch (process.argv[1]) {
@ -263,7 +260,6 @@ function installDevExtensions(isDev_) {
if (!isDev_) {
return Promise.resolve();
}
// eslint-disable-next-line import/no-extraneous-dependencies
const installer = require('electron-devtools-installer');
const extensions = ['REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS'];

View file

@ -142,7 +142,6 @@ function getPluginVersions() {
return paths_.map(path_ => {
let version = null;
try {
//eslint-disable-next-line import/no-dynamic-require
version = require(resolve(path_, 'package.json')).version;
//eslint-disable-next-line no-empty
} catch (err) {}
@ -267,7 +266,6 @@ function requirePlugins() {
const load = path_ => {
let mod;
try {
// eslint-disable-next-line import/no-dynamic-require
mod = require(path_);
const exposed = mod && Object.keys(mod).some(key => availableExtensions.has(key));
if (!exposed) {
@ -278,7 +276,6 @@ function requirePlugins() {
// populate the name for internal errors here
mod._name = basename(path_);
try {
// eslint-disable-next-line import/no-dynamic-require
mod._version = require(resolve(path_, 'package.json')).version;
} catch (err) {
//eslint-disable-next-line no-console

View file

@ -23,5 +23,7 @@ module.exports = (createWindow, selection) => {
const commandKeys = getCommandKeys(getDecoratedKeymaps());
const _shell = shellMenu(commandKeys, execCommand).submenu;
const _edit = editMenu(commandKeys, execCommand).submenu.filter(filterCutCopy.bind(null, selection));
return _edit.concat(separator, _shell).filter(menuItem => !menuItem.hasOwnProperty('enabled') || menuItem.enabled);
return _edit
.concat(separator, _shell)
.filter(menuItem => !Object.prototype.hasOwnProperty.call(menuItem, 'enabled') || menuItem.enabled);
};

View file

@ -4,13 +4,13 @@ environment:
matrix:
- platform: x64
image: Visual Studio 2015
image: Visual Studio 2017
init:
- yarn config set msvs_version 2015 # we need this to build `pty.js`
install:
- ps: Install-Product node 10.2.0 x64
- ps: Install-Product node 12 x64
- set CI=true
- yarn

View file

@ -11,7 +11,9 @@ const path = require('path');
const applicationDirectory =
process.env.XDG_CONFIG_HOME !== undefined
? path.join(process.env.XDG_CONFIG_HOME, 'hyper')
: process.platform == 'win32' ? path.join(process.env.APPDATA, 'Hyper') : os.homedir();
: process.platform == 'win32'
? path.join(process.env.APPDATA, 'Hyper')
: os.homedir();
const devConfigFileName = path.join(__dirname, `../.hyper.js`);
@ -56,8 +58,8 @@ const getProperties = memoize(() => getParsedFile().program.body.map(obj => obj)
const getPlugins = memoize(() => {
let plugins;
getProperties().find(property => {
return Object.values(property.expression.right.properties).filter(
plugin => (plugin.key.name === 'plugins' ? (plugins = plugin.value.elements) : null)
return Object.values(property.expression.right.properties).filter(plugin =>
plugin.key.name === 'plugins' ? (plugins = plugin.value.elements) : null
);
});
return plugins;
@ -66,8 +68,8 @@ const getPlugins = memoize(() => {
const getLocalPlugins = memoize(() => {
let localPlugins;
getProperties().find(property => {
return Object.values(property.expression.right.properties).filter(
plugin => (plugin.key.name === 'localPlugins' ? (localPlugins = plugin.value.elements) : null)
return Object.values(property.expression.right.properties).filter(plugin =>
plugin.key.name === 'localPlugins' ? (localPlugins = plugin.value.elements) : null
);
});
return localPlugins;

View file

@ -73,7 +73,8 @@ export default class Notifications extends React.PureComponent {
userDismissable
>
Version <b>{this.props.updateVersion}</b> ready.
{this.props.updateNote && ` ${this.props.updateNote.trim().replace(/\.$/, '')}`} (<a
{this.props.updateNote && ` ${this.props.updateNote.trim().replace(/\.$/, '')}`} (
<a
style={{color: '#000'}}
onClick={ev => {
window.require('electron').shell.openExternal(ev.target.href);
@ -82,7 +83,8 @@ export default class Notifications extends React.PureComponent {
href={`https://github.com/zeit/hyper/releases/tag/${this.props.updateVersion}`}
>
notes
</a>).{' '}
</a>
).{' '}
{this.props.updateCanInstall ? (
<a
style={{
@ -110,7 +112,8 @@ export default class Notifications extends React.PureComponent {
>
Download
</a>
)}.{' '}
)}
.{' '}
</Notification>
)}
{this.props.customChildren}

View file

@ -1,4 +1,3 @@
/* global Blob,URL,requestAnimationFrame,ResizeObserver */
import React from 'react';
import {Terminal} from 'xterm';
import * as fit from 'xterm/lib/addons/fit/fit';

View file

@ -64,7 +64,9 @@ export default class Terms extends React.Component {
componentDidMount() {
window.addEventListener('contextmenu', () => {
const selection = window.getSelection().toString();
const {props: {uid}} = this.getActiveTerm();
const {
props: {uid}
} = this.getActiveTerm();
this.props.onContextMenu(uid, selection);
});
}

View file

@ -114,7 +114,7 @@ const reducer = (state = initial, action) => {
switch (action.type) {
case CONFIG_LOAD:
// eslint-disable-next-line no-case-declarations, no-fallthrough
case CONFIG_RELOAD:
case CONFIG_RELOAD: {
const {config, now} = action;
state_ = state
// unset the user font size override if the
@ -261,7 +261,7 @@ const reducer = (state = initial, action) => {
})()
);
break;
}
case SESSION_ADD:
state_ = state.merge(
{

View file

@ -1,10 +1,12 @@
import {createSelector} from 'reselect';
const getTermGroups = ({termGroups}) => termGroups.termGroups;
const getRootGroups = createSelector(getTermGroups, termGroups =>
Object.keys(termGroups)
.map(uid => termGroups[uid])
.filter(({parentUid}) => !parentUid)
const getRootGroups = createSelector(
getTermGroups,
termGroups =>
Object.keys(termGroups)
.map(uid => termGroups[uid])
.filter(({parentUid}) => !parentUid)
);
export default getRootGroups;

View file

@ -10,7 +10,7 @@
* PR: https://github.com/kevva/executable/pull/10
*/
import fs, { Stats } from "fs";
import fs, {Stats} from "fs";
export function isExecutable(fileStat: Stats): boolean {
if (process.platform === 'win32') {

View file

@ -1,4 +1,3 @@
/* global Notification */
/* eslint no-new:0 */
export default function notify(title, body, details = {}) {
//eslint-disable-next-line no-console

View file

@ -10,7 +10,6 @@ import ReactDOM from 'react-dom';
import Notification from '../components/notification';
import notify from './notify';
//eslint-disable-next-line import/newline-after-import
const Module = require('module');
const originalLoad = Module._load;
Module._load = function _load(path) {
@ -480,9 +479,7 @@ function getDecorated(parent, name) {
if (!class__ || typeof class__.prototype.render !== 'function') {
notify(
'Plugin error',
`${
fn._pluginName
}: Invalid return value of \`${method}\`. No \`render\` method found. Please return a \`React.Component\`.`
`${fn._pluginName}: Invalid return value of \`${method}\`. No \`render\` method found. Please return a \`React.Component\`.`
);
return;
}

View file

@ -1,26 +1,32 @@
{
"repository": "zeit/hyper",
"scripts": {
"start":
"echo 'please run `yarn run dev` in one tab and then `yarn run app` in another one'",
"start": "echo 'please run `yarn run dev` in one tab and then `yarn run app` in another one'",
"app": "electron app",
"dev": "webpack -w",
"build": "cross-env NODE_ENV=production webpack",
"lint": "eslint .",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"test": "yarn run lint && yarn run test:unit",
"test:unit": "ava test/unit",
"test:unit:watch": "yarn run test:unit -- --watch",
"prepush": "yarn test",
"postinstall": "electron-builder install-app-deps && yarn run rebuild-node-pty",
"rebuild-node-pty": "electron-rebuild -f -w app/node_modules/node-pty -m app",
"dist":
"yarn run build && cross-env BABEL_ENV=production babel --out-file app/renderer/bundle.js --no-comments --minified app/renderer/bundle.js && build",
"clean":
"node ./bin/rimraf-standalone.js node_modules && node ./bin/rimraf-standalone.js ./app/node_modules && node ./bin/rimraf-standalone.js ./app/renderer"
"dist": "yarn run build && cross-env BABEL_ENV=production babel --out-file app/renderer/bundle.js --no-comments --minified app/renderer/bundle.js && build",
"clean": "node ./bin/rimraf-standalone.js node_modules && node ./bin/rimraf-standalone.js ./app/node_modules && node ./bin/rimraf-standalone.js ./app/renderer"
},
"eslintConfig": {
"plugins": ["react", "prettier"],
"extends": ["eslint:recommended", "plugin:react/recommended", "prettier"],
"plugins": [
"react",
"prettier",
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:prettier/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 8,
"sourceType": "module",
@ -36,8 +42,16 @@
"browser": true,
"node": true
},
"settings": {
"react": {
"version": "detect"
}
},
"rules": {
"func-names": ["error", "as-needed"],
"func-names": [
"error",
"as-needed"
],
"no-shadow": "error",
"no-extra-semi": 0,
"react/prop-types": 0,
@ -55,14 +69,17 @@
"bracketSpacing": false,
"semi": true,
"useTabs": false,
"parser": "babylon",
"parser": "babel",
"jsxBracketSameLine": false
}
]
},
"overrides": [
{
"files": ["app/config/config-default.js", ".hyper.js"],
"files": [
"app/config/config-default.js",
".hyper.js"
],
"rules": {
"prettier/prettier": [
"error",
@ -74,16 +91,29 @@
"bracketSpacing": false,
"semi": true,
"useTabs": false,
"parser": "babylon",
"parser": "babel",
"jsxBracketSameLine": false
}
]
}
},
{
"files": [
"**.ts",
"**.tsx"
],
"extends": [
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint"
]
}
]
},
"babel": {
"presets": ["@babel/react", "@babel/typescript"],
"presets": [
"@babel/react",
"@babel/typescript"
],
"plugins": [
[
"styled-jsx/babel",
@ -131,7 +161,9 @@
{
"from": "./build/${os}/",
"to": "./bin/",
"filter": ["hyper*"]
"filter": [
"hyper*"
]
}
],
"linux": {
@ -139,24 +171,34 @@
"target": [
{
"target": "deb",
"arch": ["x64"]
"arch": [
"x64"
]
},
{
"target": "AppImage",
"arch": ["x64"]
"arch": [
"x64"
]
},
{
"target": "rpm",
"arch": ["x64"]
"arch": [
"x64"
]
},
{
"target": "snap",
"arch": ["x64"]
"arch": [
"x64"
]
}
]
},
"win": {
"target": ["squirrel"],
"target": [
"squirrel"
],
"rfc3161TimeStampServer": "http://timestamp.comodoca.com"
},
"mac": {
@ -175,7 +217,9 @@
},
"protocols": {
"name": "ssh URL",
"schemes": ["ssh"]
"schemes": [
"ssh"
]
}
},
"license": "MIT",
@ -227,6 +271,8 @@
"@types/react": "16.9.2",
"@types/react-dom": "16.9.0",
"@types/react-redux": "7.1.2",
"@typescript-eslint/eslint-plugin": "2.3.2",
"@typescript-eslint/parser": "2.3.2",
"ava": "0.25.0",
"babel-loader": "8.0.6",
"babel-preset-minify": "0.5.1",
@ -237,15 +283,15 @@
"electron-builder-squirrel-windows": "20.38.2",
"electron-devtools-installer": "2.2.4",
"electron-rebuild": "1.8.2",
"eslint": "4.18.2",
"eslint-config-prettier": "2.6.0",
"eslint-plugin-prettier": "2.3.1",
"eslint-plugin-react": "7.3.0",
"eslint": "6.5.1",
"eslint-config-prettier": "6.3.0",
"eslint-plugin-prettier": "3.1.1",
"eslint-plugin-react": "7.15.0",
"fork-ts-checker-webpack-plugin": "1.5.0",
"husky": "0.14.3",
"inquirer": "5.1.0",
"node-gyp": "3.6.2",
"prettier": "1.11.1",
"prettier": "1.18.2",
"proxyquire": "1.8.0",
"spectron": "3.8.0",
"style-loader": "0.19.1",

View file

@ -15,7 +15,6 @@ module.exports = async markdown => {
//eslint-disable-next-line no-console
console.error('Please specify a release summary!');
// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
}

717
yarn.lock

File diff suppressed because it is too large Load diff