Skip to content

Commit f14a11a

Browse files
authored
chore: update eslint from version 7 to version 8 (#29355)
* chore: (for eslint-plugin-dev only is breaking) update eslint-plugin dev minimum to eslint 7. Remove support for coffeescript and reconfigured required peer deps * correctly configure eslint-plugin-json-format for the monorepo and run linting on all json files (previously was not running) * properly support no duplicate imports
1 parent e2dcf53 commit f14a11a

File tree

72 files changed

+1175
-845
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1175
-845
lines changed

.eslintrc.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@ module.exports = {
5959
'no-restricted-syntax': 'off',
6060
},
6161
},
62+
{
63+
files: ['*.json'],
64+
extends: 'plugin:@cypress/dev/general',
65+
},
6266
],
6367
rules: {
6468
'no-duplicate-imports': 'off',
65-
'import/no-duplicates': 'off',
66-
'@typescript-eslint/no-duplicate-imports': [
67-
'error',
68-
],
69+
'import/no-duplicates': 'error',
6970
'prefer-spread': 'off',
7071
'prefer-rest-params': 'off',
7172
'no-useless-constructor': 'off',

npm/cypress-schematic/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"scripts": {
77
"build": "tsc -p tsconfig.json",
88
"build:watch": "tsc -p tsconfig.json --watch",
9-
"test": "mocha -r @packages/ts/register --reporter mocha-multi-reporters --reporter-options configFile=../../mocha-reporter-config.json src/**/*.spec.ts",
10-
"lint": "eslint --ext .ts,.json, ."
9+
"lint": "eslint --ext .ts,.json, .",
10+
"test": "mocha -r @packages/ts/register --reporter mocha-multi-reporters --reporter-options configFile=../../mocha-reporter-config.json src/**/*.spec.ts"
1111
},
1212
"dependencies": {
1313
"jsonc-parser": "^3.0.0",

npm/cypress-schematic/src/schematics/utils/jsonFile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export type JSONPath = (string | number)[];
2525

2626
/** @internal */
2727
export class JSONFile {
28-
content: string;
28+
content: string
2929

3030
constructor (private readonly host: Tree, private readonly path: string) {
3131
const buffer = this.host.read(this.path)
@@ -37,7 +37,7 @@ export class JSONFile {
3737
}
3838
}
3939

40-
private _jsonAst: Node | undefined;
40+
private _jsonAst: Node | undefined
4141
private get JsonAst (): Node | undefined {
4242
if (this._jsonAst) {
4343
return this._jsonAst

npm/eslint-plugin-dev/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ npm install --save-dev @cypress/eslint-plugin-dev
2020

2121
## Usage
2222

23-
> ⚠️ Currently does **not** support ESLint version 8+
23+
> ⚠️ Currently does **not** support ESLint version 9
24+
25+
For Eslint 8, use version 6.x.x
26+
27+
For Eslint 7 and below, use version 5.x.x
2428

2529
1) install the following `devDependencies`:
2630
```sh
@@ -30,13 +34,9 @@ eslint-plugin-json-format
3034
@typescript-eslint/eslint-plugin
3135
eslint-plugin-mocha
3236

33-
# if you have coffeescript files
34-
@fellow/eslint-plugin-coffee
35-
babel-eslint
36-
3737
# if you have react/jsx files
3838
eslint-plugin-react
39-
babel-eslint
39+
@babel/eslint-parser
4040
```
4141

4242
2) add the following to your root level `.eslintrc.json`:
@@ -114,7 +114,7 @@ React and JSX-specific configuration and rules.
114114

115115
**requires you to install the following `devDependencies`**:
116116
```sh
117-
babel-eslint
117+
@babel/eslint-parser
118118
eslint-plugin-react
119119
```
120120

npm/eslint-plugin-dev/lib/custom-rules/arrow-body-multiline-braces.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const ruleComposer = require('eslint-rule-composer')
2-
const arrowBodyStyle = require('eslint/lib/rules/arrow-body-style')
2+
const eslint = require('eslint')
3+
const arrowBodyStyle = new eslint.Linter().getRules().get('arrow-body-style')
34

45
module.exports = ruleComposer.filterReports(
56
arrowBodyStyle,

npm/eslint-plugin-dev/lib/custom-rules/no-only.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
let astUtils
2-
3-
try {
4-
astUtils = require('eslint/lib/util/ast-utils')
5-
} catch (e) {
6-
astUtils = require('eslint/lib/shared/ast-utils')
7-
}
1+
// @see https://github.com/eslint/eslint/blob/v8.57.0/lib/shared/ast-utils.js#L12
2+
// This value is not exported anywhere, but hasn't changed in almost a decade.
3+
// we can directly reference the pattern here
4+
const lineBreakPattern = /\r\n|[\r\n\u2028\u2029]/u
85

96
module.exports = {
107
meta: {
@@ -25,7 +22,7 @@ module.exports = {
2522
const sourceCode = context.getSourceCode()
2623

2724
function getPropertyText (node) {
28-
const lines = sourceCode.getText(node).split(astUtils.LINEBREAK_MATCHER)
25+
const lines = sourceCode.getText(node).split(lineBreakPattern)
2926

3027
return lines[0]
3128
}

npm/eslint-plugin-dev/lib/index.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -238,25 +238,6 @@ module.exports = {
238238
'@cypress/dev/arrow-body-multiline-braces': 'off',
239239
},
240240
},
241-
{
242-
files: '*.coffee',
243-
parser: '@fellow/eslint-plugin-coffee',
244-
parserOptions: {
245-
parser: 'babel-eslint',
246-
sourceType: 'module',
247-
ecmaVersion: 2018,
248-
},
249-
plugins: [
250-
'@fellow/eslint-plugin-coffee',
251-
],
252-
rules: {
253-
...Object.assign({}, ...Object.keys(baseRules).map((key) => ({ [key]: 'off' }))),
254-
'@fellow/coffee/coffeescript-error': [
255-
'error',
256-
{},
257-
],
258-
},
259-
},
260241
{
261242
files: [
262243
'*.ts',
@@ -266,17 +247,15 @@ module.exports = {
266247
parser: '@typescript-eslint/parser',
267248
plugins: [
268249
'@typescript-eslint',
250+
'import',
269251
],
270252
rules: {
271253
'no-undef': 'off',
272254
'no-unused-vars': 'off',
273255
'indent': 'off',
274256
'no-useless-constructor': 'off',
275257
'no-duplicate-imports': 'off',
276-
'import/no-duplicates': 'off',
277-
'@typescript-eslint/no-duplicate-imports': [
278-
'error',
279-
],
258+
'import/no-duplicates': 'error',
280259
'@typescript-eslint/no-unused-vars': [
281260
'error',
282261
{
@@ -344,10 +323,11 @@ module.exports = {
344323
env: {
345324
browser: true,
346325
},
347-
parser: 'babel-eslint',
326+
parser: '@babel/eslint-parser',
348327
parserOptions: {
349328
ecmaVersion: 2018,
350329
sourceType: 'module',
330+
requireConfigFile: false,
351331
ecmaFeatures: {
352332
jsx: true,
353333
legacyDecorators: true,

npm/eslint-plugin-dev/lib/scripts/utils.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const path = require('path')
12
const _ = require('lodash')
23
const EE = require('events')
34
const sh = require('shelljs')
@@ -75,12 +76,13 @@ module.exports = {
7576
const filenamesString = sh.ShellString(filenames.join(' '))
7677

7778
const lintCommand = opts.fix ?
78-
`./node_modules/.bin/eslint --color=true --fix '' ${filenamesString}`
79-
: `./node_modules/.bin/eslint --color=true '' ${filenamesString}`
79+
`npx eslint --color=true --fix ${filenamesString}`
80+
: `npx eslint --color=true ${filenamesString}`
8081

82+
// always run command in the root of the monorepo!
8183
return Promise.promisify(sh.exec)(
8284
lintCommand,
83-
{ silent: false, async: true },
85+
{ silent: false, async: true, cwd: path.resolve(__dirname, '../../../../') },
8486
)
8587
.tapCatch(debugTerse)
8688
.return(false)

npm/eslint-plugin-dev/package.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@
1717
"shelljs": "0.8.5"
1818
},
1919
"devDependencies": {
20-
"eslint": "^7.22.0",
20+
"eslint": "^8.56.0",
21+
"eslint-plugin-import": "^2.29.1",
2122
"eslint-plugin-json-format": "^2.0.0",
22-
"eslint-plugin-mocha": "^8.1.0",
23+
"eslint-plugin-mocha": "^8.2.0",
2324
"eslint-plugin-promise": "^4.2.1",
2425
"sinon": "^7.3.2",
2526
"sinon-chai": "^3.3.0"
2627
},
2728
"peerDependencies": {
28-
"@typescript-eslint/eslint-plugin": ">= 1.11.0",
29-
"@typescript-eslint/parser": ">= 1.11.0",
30-
"babel-eslint": "^7.2.3",
31-
"eslint": ">= 3.2.1",
29+
"@babel/eslint-parser": "^7.0.0",
30+
"@typescript-eslint/eslint-plugin": ">= 7.0.0",
31+
"@typescript-eslint/parser": ">= 7.0.0",
32+
"eslint": "^= 8.0.0",
33+
"eslint-plugin-import": ">= 2.0.0",
3234
"eslint-plugin-json-format": ">= 2.0.0",
33-
"eslint-plugin-mocha": " >= 4.11.0",
34-
"eslint-plugin-react": "^7.22.0"
35+
"eslint-plugin-mocha": " >= 8.0.0",
36+
"eslint-plugin-react": ">= 7.22.0"
3537
},
3638
"bin": {
3739
"lint-changed": "./lib/scripts/lint-changed.js",
@@ -51,4 +53,4 @@
5153
"eslint",
5254
"eslintplugin"
5355
]
54-
}
56+
}

npm/eslint-plugin-dev/test/arrow-body-multiline-braces.spec.js

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,44 @@
11
const path = require('path')
2-
const CLIEngine = require('eslint').CLIEngine
3-
const plugin = require('..')
2+
const eslint = require('eslint')
3+
const plugin = require('../lib')
44
const _ = require('lodash')
55
const { expect } = require('chai')
66

77
const pluginName = '__plugin__'
8+
const ESLint = eslint.ESLint
89

9-
function execute (file, options = {}) {
10-
const opts = _.defaultsDeep(options, {
10+
async function execute (file, options = {}) {
11+
const defaultConfig = {
1112
fix: true,
12-
config: {
13+
ignore: false,
14+
useEslintrc: false,
15+
baseConfig: {
1316
parserOptions: {
1417
ecmaVersion: 2018,
1518
sourceType: 'module',
1619
},
20+
rules: {
21+
[`${pluginName}/arrow-body-multiline-braces`]: ['error', 'always'],
22+
},
23+
plugins: [pluginName],
1724
},
18-
19-
})
20-
21-
const cli = new CLIEngine({
22-
parserOptions: {
23-
ecmaVersion: 2018,
24-
sourceType: 'module',
25-
},
26-
rules: {
27-
[`${pluginName}/arrow-body-multiline-braces`]: ['error', 'always'],
25+
plugins: {
26+
[pluginName]: plugin,
2827
},
29-
...opts,
30-
ignore: false,
31-
useEslintrc: false,
32-
plugins: [pluginName],
33-
})
28+
}
29+
const opts = _.defaultsDeep(options, defaultConfig)
30+
31+
const cli = new ESLint(opts)
3432

35-
cli.addPlugin(pluginName, plugin)
36-
const results = cli.executeOnFiles([path.join(__dirname, file)]).results[0]
33+
const results = await cli.lintFiles([path.join(__dirname, file)])
3734

38-
return results
35+
return results[0]
3936
}
4037

4138
describe('arrow-body-multiline-braces', () => {
4239
it('lint multiline js', async () => {
4340
const filename = './fixtures/multiline.js'
44-
const result = execute(filename, {
41+
const result = await execute(filename, {
4542
fix: true,
4643
})
4744

@@ -50,7 +47,7 @@ describe('arrow-body-multiline-braces', () => {
5047

5148
it('lint oneline js', async () => {
5249
const filename = './fixtures/oneline.js'
53-
const result = execute(filename, { fix: false })
50+
const result = await execute(filename, { fix: false })
5451

5552
expect(result.output).not.ok
5653
expect(result.errorCount).eq(0)

npm/eslint-plugin-dev/test/no-only.spec.js

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,45 @@
11
const path = require('path')
2-
const CLIEngine = require('eslint').CLIEngine
2+
const eslint = require('eslint')
33
const plugin = require('..')
44
const _ = require('lodash')
55
const { expect } = require('chai')
66

77
const ruleName = 'no-only'
88
const pluginName = '__plugin__'
9+
const ESLint = eslint.ESLint
910

10-
function execute (file, options = {}) {
11-
const opts = _.defaultsDeep(options, {
11+
async function execute (file, options = {}) {
12+
const defaultConfig = {
1213
fix: true,
13-
config: {
14+
ignore: false,
15+
useEslintrc: false,
16+
baseConfig: {
1417
parserOptions: {
1518
ecmaVersion: 2018,
1619
sourceType: 'module',
1720
},
21+
rules: {
22+
[`${pluginName}/${ruleName}`]: ['error'],
23+
},
24+
plugins: [pluginName],
1825
},
19-
})
20-
21-
const cli = new CLIEngine({
22-
parserOptions: {
23-
ecmaVersion: 2018,
24-
sourceType: 'module',
25-
},
26-
rules: {
27-
[`${pluginName}/${ruleName}`]: ['error'],
26+
plugins: {
27+
[pluginName]: plugin,
2828
},
29-
...opts,
30-
ignore: false,
31-
useEslintrc: false,
32-
plugins: [pluginName],
33-
})
29+
}
30+
const opts = _.defaultsDeep(options, defaultConfig)
31+
32+
const cli = new ESLint(opts)
3433

35-
cli.addPlugin(pluginName, plugin)
36-
const results = cli.executeOnFiles([path.join(__dirname, file)]).results[0]
34+
const results = await cli.lintFiles([path.join(__dirname, file)])
3735

38-
return results
36+
return results[0]
3937
}
4038

4139
describe('no-only', () => {
4240
it('lint js with only', async () => {
4341
const filename = './fixtures/with-only.js'
44-
const result = execute(filename, {
42+
const result = await execute(filename, {
4543
fix: true,
4644
})
4745

0 commit comments

Comments
 (0)