Skip to content

Commit

Permalink
Improve esling config (hello-pangea#39)
Browse files Browse the repository at this point in the history
* (tools) include more files in our eslint config and elint jest config to test folder

* (fix) disabling some rule for a11y audit

* Remove node version in eslint config
  • Loading branch information
100terres authored Jan 11, 2021
1 parent 0932017 commit 7271515
Show file tree
Hide file tree
Showing 17 changed files with 415 additions and 342 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

# https://github.com/eslint/eslint/issues/8429#issuecomment-355967308
!.storybook
!**/*.eslintrc.js

dist/
flow-typed/
site/
coverage/
babel.config.js
83 changes: 54 additions & 29 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,22 @@ module.exports = {
'plugin:flowtype/recommended',
'prettier/react',
'prettier/flowtype',
'plugin:jest/recommended',
'plugin:prettier/recommended',
],
parser: 'babel-eslint',
plugins: [
'prettier',
'flowtype',
'emotion',
'@emotion',
'react',
'react-hooks',
'import',
'jest',
'es5',
],
parser: '@babel/eslint-parser',
env: {
es6: true,
browser: true,
node: true,
'jest/globals': true,
},
globals: {
// flow globals
Expand Down Expand Up @@ -208,21 +205,8 @@ module.exports = {

// don't need to initialize state in a constructor
'react/state-in-constructor': 'off',

'jest/expect-expect': [
'error',
{
assertFunctionNames: [
'expect',
// these functions will run expect internally
'withWarn',
'withError',
'withoutError',
'withoutWarn',
],
},
],
},

overrides: [
// Forbid using not es5 methods
{
Expand All @@ -236,29 +220,70 @@ module.exports = {
},
},

// NodeJS files
{
extends: ['plugin:node/recommended'],
files: [
'**/*.eslintrc.js',
'a11y-audit-parse.js',
'browser-test-harness.js',
'babel.config.js',
'jest.config.js',
'lighthouse.config.js',
'rollup.config.js',
'server-ports.js',
],
rules: {
'flowtype/require-valid-file-annotation': 'off',
},
},

{
extends: ['plugin:node/recommended-module'],
parserOptions: {
project: './tsconfig.json',
ecmaVersion: 2020,
sourceType: 'module',
},
env: {
browser: false,
es6: false,
},
files: ['rollup.config.js'],
rules: {
'flowtype/require-valid-file-annotation': 'off',
'node/no-unsupported-features/es-syntax': [
'error',
{
ignores: ['modules'],
},
],
},
},

// Typescript files
{
parser: '@typescript-eslint/parser',
extends: [
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended',
'plugin:import/typescript',
'prettier/@typescript-eslint',
],
plugins: ['@typescript-eslint'],
parser: '@typescript-eslint/parser',
files: ['**/*.ts?(x)'],
rules: {
'flowtype/no-types-missing-file-annotation': 'off',
'flowtype/require-valid-file-annotation': 'off',

"import/extensions": [
"error",
"ignorePackages",
'import/extensions': [
'error',
'ignorePackages',
{
"js": "never",
"jsx": "never",
"ts": "never",
"tsx": "never"
}
js: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
},
],

'no-use-before-define': 'off',
Expand Down
2 changes: 1 addition & 1 deletion .storybook/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
rules: {
'flowtype/require-valid-file-annotation': 'off',
'no-console': "off",
'no-console': 'off',
},
};
14 changes: 7 additions & 7 deletions .storybook/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { plugins, presets } = require('@storybook/core/dist/server/common/babel');
const {
plugins,
presets,
} = require('@storybook/core/dist/server/common/babel');

module.exports = {
plugins,
presets: [
...presets,
'@emotion/babel-preset-css-prop',
],
comments: false
}
presets: [...presets, '@emotion/babel-preset-css-prop'],
comments: false,
};
44 changes: 16 additions & 28 deletions a11y-audit-parse.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
/* eslint-disable flowtype/require-valid-file-annotation */
/* eslint-disable import/no-unresolved */
/* eslint-disable global-require */
/* eslint-disable no-console */
try {
// I disabled flow for this file because of this line.
// Sometimes the file exists, sometimes it doesn't.
// It depends on if you have run the accessibility test or not.
// Given this conditional I thought it best to simply disable flow for the file
const a11yReport = require('./test-reports/lighthouse/a11y.report.json');
const a11yScore = a11yReport.categories.accessibility.score;
const a11yScoreFormatted = `${a11yScore ? a11yScore * 100 : 0}%`;
// eslint-disable-next-line import/no-unresolved, node/no-missing-require
const a11yReport = require('./test-reports/lighthouse/a11y.report.json');

const a11yScore = a11yReport.categories.accessibility.score;
const a11yScoreFormatted = `${a11yScore ? a11yScore * 100 : 0}%`;

console.log('*************************');
console.log('Lighthouse accessibility score: ', a11yScoreFormatted);
console.log('*************************');
/* eslint-disable no-console */
console.log('*************************');
console.log('Lighthouse accessibility score: ', a11yScoreFormatted);
console.log('*************************');
/* eslint-enable no-console */

if (a11yScore === 1) {
// success!
process.exit(0);
} else {
// fail build
console.log(
'\nNOTE: Lighthouse accessibility audit score must be 100% to pass this build step.\n\n',
);
process.exit(1);
}
} catch (e) {
console.error(e);
process.exit(1);
if (a11yScore !== 1) {
// fail build
// eslint-disable-next-line no-restricted-syntax
throw new Error(
'NOTE: Lighthouse accessibility audit score must be 100% to pass this build step.',
);
}
19 changes: 10 additions & 9 deletions browser-test-harness.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @flow
const childProcess = require('child_process');
const path = require('path');
const waitPort = require('wait-port');
Expand Down Expand Up @@ -37,27 +36,29 @@ Promise.all([
])
.then(() => {
if (!process.argv[2]) {
// eslint-disable-next-line no-console
console.warn('Started servers but no command supplied to run after');
process.exit();
// eslint-disable-next-line no-restricted-syntax
throw new Error('Started servers but no command supplied to run after');
}

const child = childProcess.spawn(process.argv[2], process.argv.slice(3), {
stdio: 'inherit',
});

process.on('exit', () => {
child.kill();
});

child.on('exit', (code) => {
// eslint-disable-next-line no-process-exit
process.exit(code);
});
})
.catch((error) => {
// eslint-disable-next-line no-console
console.error('Unable to spin up standalone servers');
// eslint-disable-next-line no-console
console.error(error);
storybook.kill();
cspServer.kill();
process.exit(1);

// eslint-disable-next-line no-console
console.error(error);
// eslint-disable-next-line no-restricted-syntax
throw new Error('Unable to spin up standalone servers');
});
1 change: 0 additions & 1 deletion cypress/integration/reorder-virtual.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ describe('reorder: virtual', () => {

// This is setting up a chain of commands and this test will not wait
// for a 'promise' to resolve. Linting is getting confused by .then
// eslint-disable-next-line jest/valid-expect-in-promise
cy.get('@item-id').then((id) => {
cy.get(getHandleSelector(id))
.invoke('attr', 'data-index')
Expand Down
3 changes: 1 addition & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable flowtype/require-valid-file-annotation */

module.exports = {
setupFiles: [
// for some painful reason this is needed for our 'async' usage
// in drop-dev-warnings-for-prod.spec.js
// eslint-disable-next-line node/no-extraneous-require
require.resolve('regenerator-runtime/runtime'),
'./test/env-setup.js',
],
Expand Down
1 change: 0 additions & 1 deletion lighthouse.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable flowtype/require-valid-file-annotation */
module.exports = {
extends: 'lighthouse:default',
settings: {
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"@atlaskit/css-reset": "^5.0.10",
"@atlaskit/theme": "^11.0.2",
"@babel/core": "^7.12.10",
"@babel/eslint-parser": "^7.12.1",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/plugin-transform-modules-commonjs": "^7.12.1",
"@babel/plugin-transform-object-assign": "^7.12.1",
Expand All @@ -83,6 +84,7 @@
"@babel/preset-react": "^7.12.10",
"@emotion/babel-preset-css-prop": "^10.0.27",
"@emotion/core": "^10.0.28",
"@emotion/eslint-plugin": "^11.0.0",
"@emotion/styled": "^10.0.27",
"@rollup/plugin-babel": "^5.2.2",
"@rollup/plugin-commonjs": "^17.0.0",
Expand All @@ -99,10 +101,8 @@
"@types/react-dom": "^16.9.10",
"@types/react-virtualized": "^9.21.10",
"@types/react-window": "^1.8.2",
"@typescript-eslint/eslint-plugin": "^4.10.0",
"@typescript-eslint/parser": "^4.10.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.1.0",
"@typescript-eslint/eslint-plugin": "^4.11.1",
"@typescript-eslint/parser": "^4.11.1",
"babel-jest": "^26.6.3",
"babel-loader": "^8.1.0",
"babel-plugin-dev-expression": "^0.2.2",
Expand All @@ -114,19 +114,19 @@
"emotion-theming": "^10.0.27",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "6.8.0",
"eslint-config-airbnb": "^18.1.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-cypress": "^2.10.3",
"eslint-plugin-emotion": "^10.0.27",
"eslint": "^7.16.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-cypress": "^2.11.2",
"eslint-plugin-es5": "^1.5.0",
"eslint-plugin-flowtype": "^4.7.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-flowtype": "^5.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-react-hooks": "^3.0.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.0",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"flow-bin": "0.110.1",
"fs-extra": "^9.0.0",
"globby": "^11.0.0",
Expand Down
2 changes: 0 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable flowtype/require-valid-file-annotation */

import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
Expand Down
1 change: 0 additions & 1 deletion server-ports.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @flow
const ports = {
storybook: 9002,
cspServer: 9003,
Expand Down
Loading

0 comments on commit 7271515

Please sign in to comment.