Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

chore(package): add ESLint #600

Merged
merged 18 commits into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.awcache/
coverage/
dist/
dll/
node_modules/
4 changes: 4 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["./packages/internal-tooling/eslint/index.js"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paths are not great, should be fixed in ESLint 6: eslint/eslint#11388

"root": true
}
8 changes: 0 additions & 8 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
.github/

# editor configs
.idea/
.vscode/


coverage/

dist/
dll/
docs/src/componentInfo
docs/src/componentMenu.json
docs/src/behaviorMenu.json
docs/src/exampleMenus
docs/dist/
stats/

package.json
12 changes: 2 additions & 10 deletions .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@
"$schema": "http://json.schemastore.org/prettierrc",
"htmlWhitespaceSensitivity": "ignore",
"printWidth": 100,
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"trailingComma": "all",
"overrides": [
{
"files": ".prettierrc",
"options": {
"parser": "json"
}
}
]
"tabWidth": 2,
"trailingComma": "all"
}
1 change: 1 addition & 0 deletions build/gulp/plugins/util/parseType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const _ = require('lodash')

// eslint-disable-next-line no-eval
const evalValue = value => eval(value) // tslint:disable-line no-eval

const isTransformable = value => typeof value === 'string' && value.includes('names')
Expand Down
11 changes: 5 additions & 6 deletions build/gulp/sh.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { spawn } from 'child_process'
import * as childProcess from 'child_process'

const sh = (command: string, pipeOutputToResult: boolean = false): Promise<string> => {
return new Promise((resolve, reject) => {
const sh = (command: string, pipeOutputToResult: boolean = false): Promise<string> =>
new Promise((resolve, reject) => {
const [cmd, ...args] = command.split(' ')

const options = {
const options: childProcess.SpawnOptions = {
cwd: process.cwd(),
env: process.env,
stdio: pipeOutputToResult ? 'pipe' : [0, 1, 2],
shell: true,
}

const child = spawn(cmd, args, options)
const child = childProcess.spawn(cmd, args, options)

let stdoutData = ''

Expand All @@ -29,6 +29,5 @@ const sh = (command: string, pipeOutputToResult: boolean = false): Promise<strin
reject(new Error(`child process exited with code ${code}`))
})
})
}

export default sh
5 changes: 5 additions & 0 deletions build/gulp/tasks/test-projects/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"import/no-unresolved": "off"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have requires for Enzyme, Simulant and other stuff that it's not in direct dependencies. Currently disabled

}
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
"clean:cache": "gulp clean:cache",
"predeploy:docs": "cross-env NODE_ENV=production yarn build:docs",
"deploy:docs": "gulp deploy:docs",
"lint": "cross-env NODE_OPTIONS='-r ts-node/register' tslint -t stylish -p . --rules-dir ./build/tslint",
"lint:fix": "yarn lint --fix",
"lint": "eslint \"**/*.{js,ts,tsx}\" && yarn lint:old",
"lint:fix": "yarn lint --fix && yarn lint:old --fix",
"lint:old": "cross-env NODE_OPTIONS='-r ts-node/register' tslint -t stylish -p . --rules-dir ./build/tslint",
"perf": "cross-env PERF=true gulp perf --times=50",
"perf:debug": "cross-env PERF=true gulp perf:debug --debug",
"prettier": "prettier --list-different \"**/*.{ts,tsx}\"",
Expand Down Expand Up @@ -39,6 +40,7 @@
"**/*.{ts,tsx}": [
"prettier --write",
"tslint -t stylish --fix",
"eslint --fix",
"git add"
],
"**/*.{js,json}": [
Expand Down
122 changes: 122 additions & 0 deletions packages/internal-tooling/eslint/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
module.exports = {
extends: ['airbnb', 'plugin:prettier/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'jest', 'import', 'prettier', 'react-hooks'],
env: {
browser: true,
'jest/globals': true,
},
rules: {
// False positive on arg types:
// https://github.com/typescript-eslint/typescript-eslint/issues/46
// '@typescript-eslint/no-unused-vars': ['error', { args: 'none' }],
'import/no-unresolved': 'off',
'prettier/prettier': 'error',
'react/jsx-filename-extension': ['error', { extensions: ['.js', '.tsx'] }],
semi: ['error', 'never'],

// Temporary disabled rules
'@typescript-eslint/no-unused-vars': 'off',
'jsx-a11y/click-events-have-key-events': 'off',
'jsx-a11y/no-static-element-interactions': 'off',
'jsx-a11y/alt-text': 'off',
'jsx-a11y/anchor-is-valid': 'off',
'jsx-a11y/label-has-for': 'off',
'jsx-a11y/label-has-associated-control': 'off',
'jsx-a11y/no-noninteractive-tabindex': 'off',
'import/export': 'off',
'import/first': 'off',
'import/order': 'off',
'import/no-dynamic-require': 'off',
'import/no-extraneous-dependencies': 'off',
'import/no-named-default': 'off',
'import/no-useless-path-segments': 'off',
'import/newline-after-import': 'off',
'import/prefer-default-export': 'off',
'react/button-has-type': 'off',
'react/destructuring-assignment': 'off',
'react/default-props-match-prop-types': 'off',
'react/jsx-curly-brace-presence': 'off',
'react/jsx-boolean-value': 'off',
'react/jsx-no-bind': 'off',
'react/jsx-one-expression-per-line': 'off',
'react/jsx-pascal-case': 'off',
'react/jsx-wrap-multilines': 'off',
'react/no-access-state-in-setstate': 'off',
'react/no-children-prop': 'off',
'react/no-array-index-key': 'off',
'react/no-find-dom-node': 'off',
'react/jsx-no-target-blank': 'off',
'react/forbid-prop-types': 'off',
'react/prefer-stateless-function': 'off',
'react/no-multi-comp': 'off',
'react/no-unused-prop-types': 'off',
'react/no-unused-state': 'off',
'react/no-unescaped-entities': 'off',
'react/prop-types': 'off',
'react/require-default-props': 'off',
'react/sort-comp': 'off',
'react/no-string-refs': 'off',
'react/no-render-return-value': 'off',
camelcase: 'off',
'class-methods-use-this': 'off',
'consistent-return': 'off',
'default-case': 'off',
'dot-notation': 'off',
'global-require': 'off',
'guard-for-in': 'off',
'lines-between-class-members': 'off',
'no-await-in-loop': 'off',
'no-bitwise': 'off',
'no-case-declarations': 'off',
'no-empty': 'off',
'no-continue': 'off',
'no-extra-boolean-cast': 'off',
'no-fallthrough': 'off',
'no-nested-ternary': 'off',
'no-param-reassign': 'off',
'no-plusplus': 'off',
'no-prototype-builtins': 'off',
'no-return-await': 'off',
'no-return-assign': 'off',
'no-restricted-globals': 'off',
'no-restricted-syntax': 'off',
'no-throw-literal': 'off',
'no-sparse-arrays': 'off',
'no-shadow': 'off',
'no-undef': 'off',
'no-undef-init': 'off',
'no-underscore-dangle': 'off',
'no-unused-expressions': 'off',
'no-useless-return': 'off',
'no-unused-vars': 'off',
'no-empty-function': 'off',
'no-useless-constructor': 'off',
'no-useless-escape': 'off',
'no-use-before-define': 'off',
'operator-assignment': 'off',
'prefer-destructuring': 'off',
'spaced-comment': 'off',
},
overrides: [
{
files: '**/jest.config.js',
rules: {
'global-require': 'off',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's safe to use require() there

},
},
{
files: '**/test/**/*.{ts,tsx}',
rules: {
'import/no-extraneous-dependencies': 'off',
},
},
],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
}
11 changes: 11 additions & 0 deletions packages/internal-tooling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@
"@babel/preset-typescript": "^7.3.3",
"@types/jest": "^24.0.11",
"@types/jest-axe": "^2.2.3",
"@typescript-eslint/eslint-plugin": "^1.6.0",
"@typescript-eslint/parser": "^1.6.0",
"babel-jest": "^24.5.0",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.12.4",
"eslint-plugin-react-hooks": "^1.6.0",
"jest": "^24.5.0",
"jest-axe": "^3.1.1"
},
Expand Down
1 change: 1 addition & 0 deletions packages/react-proptypes/src/leven.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copy of sindre's leven, wrapped in dead code elimination for production
// https://github.com/sindresorhus/leven/blob/master/index.js
/* eslint-disable */

let leven = (a, b) => 0

Expand Down
1 change: 1 addition & 0 deletions packages/react/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/themes/teams/components/Icon/svg/ProcessedIcons
12 changes: 12 additions & 0 deletions packages/react/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": ["../internal-tooling/eslint/index.js"],
"overrides": [
{
"files": "**/icons/*.tsx",
"rules": {
"react/prop-types": "off"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESLint with React plugin handles these icons as React components, it will be very strange to have there propTypes...

}
}
],
"root": true
}
1 change: 1 addition & 0 deletions packages/react/src/lib/whatInput.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import isBrowser from './isBrowser'

// Taken from https://github.com/ten1seven/what-input/blob/master/src/scripts/what-input.js
/* eslint-disable */

/*
* variables
Expand Down
Loading