Skip to content

Commit

Permalink
[core] Align the eslint configuration with the main repository (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored Jul 2, 2020
1 parent 825445c commit 59d5336
Show file tree
Hide file tree
Showing 17 changed files with 341 additions and 99 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ jobs:
- run:
name: '`yarn prettier` changes committed?'
command: yarn prettier check-changed
- run:
name: Lint
command: yarn lint:ci
workflows:
version: 2
pipeline:
Expand Down
129 changes: 96 additions & 33 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,99 @@
const confusingBrowserGlobals = require('confusing-browser-globals');
const path = require('path');

module.exports = {
parser: "@typescript-eslint/parser", // Specifies the ESLint parser
extends: [
"plugin:react/recommended", // Uses the recommended rules from @eslint-plugin-react
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin
"prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
"plugin:prettier/recommended", // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
root: true, // So parent files don't get applied
globals: {
preval: false, // Used in the documentation
},
env: {
es6: true,
browser: true,
node: true,
},
extends: ['airbnb', 'prettier', 'prettier/react'],
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 7,
sourceType: 'module',
},
plugins: ['babel', 'react-hooks'],
settings: {},
/**
* Sorted alphanumerically within each group. built-in and each plugin form
* their own groups.
*/
rules: {
'consistent-this': ['error', 'self'],
'linebreak-style': 'off', // Doesn't play nicely with Windows
// just as bad as "max components per file"
'max-classes-per-file': 'off',
'no-alert': 'error',
// Strict, airbnb is using warn; allow warn and error for dev environments
'no-console': ['error', { allow: ['warn', 'error'] }],
'no-constant-condition': 'error',
// Airbnb use error
'no-param-reassign': 'off',
'no-prototype-builtins': 'off',
'no-restricted-imports': [
'error',
{
patterns: [
'@material-ui/*/*/*',
'!@material-ui/core/test-utils/*',
'!@material-ui/utils/macros/*.macro',
],
},
],
plugins: [
"unused-imports" ,
"react-hooks"
'nonblock-statement-body-position': 'error',
// Airbnb restricts isNaN and isFinite which are necessary for IE 11
// we have to be disciplined about the usage and ensure the Number type for its
// arguments
'no-restricted-globals': ['error'].concat(confusingBrowserGlobals),
'no-underscore-dangle': 'error',
'prefer-arrow-callback': ['error', { allowNamedFunctions: true }],
'prefer-destructuring': 'off', // Destructuring harm grep potential.

'jsx-a11y/label-has-associated-control': 'off',
'jsx-a11y/label-has-for': 'off', // deprecated
'jsx-a11y/no-autofocus': 'off', // We are a library, people do what they want.

// This rule is great for raising people awareness of what a key is and how it works.
'react/no-array-index-key': 'off',
'react/destructuring-assignment': 'off',
// It's buggy
'react/forbid-prop-types': 'off',
'react/jsx-curly-brace-presence': 'off',
// prefer <React.Fragment> over <>. The former allows `key` while the latter doesn't
'react/jsx-fragments': ['error', 'element'],
'react/jsx-filename-extension': ['error', { extensions: ['.js'] }], // airbnb is using .jsx
'react/jsx-handler-names': [
'error',
{
// airbnb is disabling this rule
eventHandlerPrefix: 'handle',
eventHandlerPropPrefix: 'on',
},
],
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: "module", // Allows for the use of imports
ecmaFeatures: {
jsx: true // Allows for the parsing of JSX
}
},
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-imports-ts": 2,
"unused-imports/no-unused-vars-ts": 1,
"react/prop-types": 0,
"eslint-disable react/display-name":0,
"react-hooks/rules-of-hooks": "error", // Checks rules of Hooks
"react-hooks/exhaustive-deps": "error" // Checks effect dependencies
},
settings: {
react: {
version: "detect" // Tells eslint-plugin-react to automatically detect the version of React to use
}
}
};
// not a good rule for components close to the DOM
'react/jsx-props-no-spreading': 'off',
'react/no-danger': 'error',
// Strict, airbnb is using off
'react/no-direct-mutation-state': 'error',
'react/no-find-dom-node': 'off',
'react/no-multi-comp': 'off',
'react/require-default-props': 'off',
'react/sort-prop-types': 'error',
// This depends entirely on what you're doing. There's no universal pattern
'react/state-in-constructor': 'off',
// stylistic opinion. For conditional assignment we want it outside, otherwise as static
'react/static-property-placement': 'off',

'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': ['error', { additionalHooks: 'useEnhancedEffect' }],

'import/no-unresolved': 'off',
'import/no-extraneous-dependencies': 'off',
},
overrides: [],
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

.DS_STORE
*.log
/.eslintcache
dist
node_modules
__diff_output__
38 changes: 22 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,49 @@
"author": "Damien Tassone",
"private": true,
"devDependencies": {
"@material-ui/core": "^4.9.12",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.54",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"@types/enzyme": "^3.10.5",
"@types/enzyme-adapter-react-16": "^1.0.6",
"@types/enzyme": "^3.10.5",
"@types/jest": "^25.1.2",
"@types/node": "^12.0.0",
"@types/react": "^16.9.25",
"@types/react-dom": "^16.9.5",
"@types/react": "^16.9.25",
"@types/styled-components": "^5.0.1",
"@typescript-eslint/eslint-plugin": "^2.19.0",
"@typescript-eslint/parser": "^2.19.0",
"@material-ui/core": "^4.9.12",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.54",
"styled-components": "^5.1.0",
"enzyme": "^3.11.0",
"babel-eslint": "^10.1.0",
"confusing-browser-globals": "^1.0.9",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "^6.8.0",
"enzyme": "^3.11.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.18.3",
"eslint-plugin-react-hooks": "^2.5.0",
"eslint-plugin-react": "^7.18.3",
"eslint-plugin-unused-imports": "^0.1.2",
"eslint": "^6.8.0",
"glob-gitignore": "^1.0.14",
"jest": "^25.1.0",
"jest-cli": "^25.1.0",
"jest-transform-stub": "^2.0.0",
"jest": "^25.1.0",
"lerna": "^3.20.2",
"prettier": "^1.19.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"stylelint": "^13.3.3",
"react": "^16.13.1",
"styled-components": "^5.1.0",
"stylelint-config-recommended": "^3.0.0",
"stylelint-config-standard": "^20.0.0",
"stylelint-config-styled-components": "^0.1.1",
"stylelint-processor-styled-components": "^1.10.0",
"stylelint": "^13.3.3",
"ts-jest": "^25.2.0"
},
"scripts": {
Expand All @@ -51,17 +57,17 @@
"start": "lerna run start --parallel",
"prettier": "node ./scripts/prettier.js",
"test": "lerna run test --parallel",
"lint": "lerna run lint --parallel"
"lint": "eslint . --cache --report-unused-disable-directives",
"lint:ci": "eslint . --report-unused-disable-directives",
"lint:fix": "eslint . --cache --fix"
},
"eslintConfig": {
"extends": "react-app"
},
"setupFiles": [
"<rootDir>/src/setupTests.js"
],
"dependencies": {
"styled-components": "^5.1.0"
},
"dependencies": {},
"workspaces": [
"packages/*",
"!packages/grid",
Expand Down
3 changes: 0 additions & 3 deletions packages/demo-app/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ const CopyPlugin = require('copy-webpack-plugin');
module.exports = {
context: __dirname,
entry: ['./src/index.tsx'],
optimization: {
usedExports: true,
},
resolve: {
modules: [
path.resolve(__dirname, 'node_modules'),
Expand Down
4 changes: 2 additions & 2 deletions packages/grid/data-grid/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import resolve from '@rollup/plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import pkg from './package.json';
import cleaner from 'rollup-plugin-cleaner';
import sourceMaps from 'rollup-plugin-sourcemaps';
import { terser } from 'rollup-plugin-terser';
import dts from 'rollup-plugin-dts';
import command from 'rollup-plugin-command';
import pkg from './package.json';

// dev build if watching, prod build if not
const production = !process.env.ROLLUP_WATCH;
Expand All @@ -28,7 +28,7 @@ export default [
external: [...Object.keys(pkg.peerDependencies || {})],
plugins: [
resolve({
resolveOnly: [/^@material-ui\/x\-.*$/], //we bundle x-license and x-grid-modules
resolveOnly: [/^@material-ui\/x-.*$/], // we bundle x-license and x-grid-modules
}),
production &&
cleaner({
Expand Down
5 changes: 2 additions & 3 deletions packages/grid/x-grid-data-generator/bin/data-gen-script.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env node

require = require('esm')(module /*, options*/);

// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line no-global-assign
require = require('esm')(module);

require('../dist/index-cjs').datagenCli(process.argv);
22 changes: 0 additions & 22 deletions packages/grid/x-grid-data-generator/bin/data-gen-script_BAK.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/grid/x-grid-data-generator/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import typescript from 'rollup-plugin-typescript2';
import pkg from './package.json';
import cleaner from 'rollup-plugin-cleaner';
import sourceMaps from 'rollup-plugin-sourcemaps';
import { terser } from 'rollup-plugin-terser';
import css from 'rollup-plugin-css-only';
import commonjs from 'rollup-plugin-commonjs';
import postcss from 'rollup-plugin-postcss';
import dts from 'rollup-plugin-dts';
import pkg from './package.json';

// dev build if watching, prod build if not
const production = !process.env.ROLLUP_WATCH;
Expand Down
2 changes: 1 addition & 1 deletion packages/grid/x-grid-modules/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import typescript from 'rollup-plugin-typescript2';
import pkg from './package.json';
import cleaner from 'rollup-plugin-cleaner';
import sourceMaps from 'rollup-plugin-sourcemaps';
import { terser } from 'rollup-plugin-terser';
import dts from 'rollup-plugin-dts';
import pkg from './package.json';

// dev build if watching, prod build if not
const production = !process.env.ROLLUP_WATCH;
Expand Down
4 changes: 2 additions & 2 deletions packages/grid/x-grid/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import typescript from 'rollup-plugin-typescript2';
import { generateReleaseInfo } from '@material-ui/x-license';
import pkg from './package.json';
import cleaner from 'rollup-plugin-cleaner';
import sourceMaps from 'rollup-plugin-sourcemaps';
import { terser } from 'rollup-plugin-terser';
import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import dts from 'rollup-plugin-dts';
import command from 'rollup-plugin-command';
import pkg from './package.json';

// dev build if watching, prod build if not
const production = !process.env.ROLLUP_WATCH;
Expand All @@ -33,7 +33,7 @@ export default [
__RELEASE_INFO__: generateReleaseInfo(),
}),
resolve({
resolveOnly: [/^@material-ui\/x\-.*$/], //we bundle x-license and x-grid-modules
resolveOnly: [/^@material-ui\/x-.*$/], // we bundle x-license and x-grid-modules
}),
production &&
cleaner({
Expand Down
5 changes: 2 additions & 3 deletions packages/license/bin/license-gen-script.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env node

require = require('esm')(module /*, options*/);

// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line no-global-assign
require = require('esm')(module);

require('../dist/cjs/license-cli').licenseGenCli(process.argv);
2 changes: 1 addition & 1 deletion packages/license/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import typescript from 'rollup-plugin-typescript2';
import pkg from './package.json';
import cleaner from 'rollup-plugin-cleaner';
import sourceMaps from 'rollup-plugin-sourcemaps';
import { terser } from 'rollup-plugin-terser';
import commonjs from 'rollup-plugin-commonjs';
import dts from 'rollup-plugin-dts';
import pkg from './package.json';

// dev build if watching, prod build if not
const production = !process.env.ROLLUP_WATCH;
Expand Down
2 changes: 1 addition & 1 deletion packages/panel/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import typescript from 'rollup-plugin-typescript2';
import pkg from './package.json';
import cleaner from 'rollup-plugin-cleaner';
import sourceMaps from 'rollup-plugin-sourcemaps';
import { terser } from 'rollup-plugin-terser';
import pkg from './package.json';

// dev build if watching, prod build if not
const production = !process.env.ROLLUP_WATCH;
Expand Down
2 changes: 1 addition & 1 deletion packages/splitter/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import typescript from 'rollup-plugin-typescript2';
import pkg from './package.json';
import cleaner from 'rollup-plugin-cleaner';
import sourceMaps from 'rollup-plugin-sourcemaps';
import { terser } from 'rollup-plugin-terser';
import pkg from './package.json';

// dev build if watching, prod build if not
const production = !process.env.ROLLUP_WATCH;
Expand Down
1 change: 1 addition & 0 deletions packages/storybook/integration/setup/setupTests.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { toMatchImageSnapshot } = require('jest-image-snapshot');

// eslint-disable-next-line no-undef
expect.extend({ toMatchImageSnapshot });
Loading

0 comments on commit 59d5336

Please sign in to comment.