Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update eslint from version 7 to version 8 #29355

Merged
merged 3 commits into from
Apr 26, 2024
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
9 changes: 5 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ module.exports = {
'no-restricted-syntax': 'off',
},
},
{
files: ['*.json'],
extends: 'plugin:@cypress/dev/general',
},
],
rules: {
'no-duplicate-imports': 'off',
'import/no-duplicates': 'off',
'@typescript-eslint/no-duplicate-imports': [
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean duplicate imports are now allowed? I added a duplicate import to a file and yarn lint passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

weird the rule was renamed. I'll double check and make sure I implemented it correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK I see what happened. so the rule was deprecated for import/no-duplicates which we have set to off but we really should have it turned on. However, the rule comes from import/no-duplicates which was referenced in @cypress/eslint-plugin-dev but not installed or configured (likely resolved from the root of the monorepo). I added the dependency to the package and configured the plugin correctly, so the linting rules for duplicate imports should now work correctly. done in e6e262f

'error',
],
'import/no-duplicates': 'error',
'prefer-spread': 'off',
'prefer-rest-params': 'off',
'no-useless-constructor': 'off',
Expand Down
4 changes: 2 additions & 2 deletions npm/cypress-schematic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"scripts": {
"build": "tsc -p tsconfig.json",
"build:watch": "tsc -p tsconfig.json --watch",
"test": "mocha -r @packages/ts/register --reporter mocha-multi-reporters --reporter-options configFile=../../mocha-reporter-config.json src/**/*.spec.ts",
"lint": "eslint --ext .ts,.json, ."
"lint": "eslint --ext .ts,.json, .",
"test": "mocha -r @packages/ts/register --reporter mocha-multi-reporters --reporter-options configFile=../../mocha-reporter-config.json src/**/*.spec.ts"
},
"dependencies": {
"jsonc-parser": "^3.0.0",
Expand Down
4 changes: 2 additions & 2 deletions npm/cypress-schematic/src/schematics/utils/jsonFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type JSONPath = (string | number)[];

/** @internal */
export class JSONFile {
content: string;
content: string

constructor (private readonly host: Tree, private readonly path: string) {
const buffer = this.host.read(this.path)
Expand All @@ -37,7 +37,7 @@ export class JSONFile {
}
}

private _jsonAst: Node | undefined;
private _jsonAst: Node | undefined
private get JsonAst (): Node | undefined {
if (this._jsonAst) {
return this._jsonAst
Expand Down
14 changes: 7 additions & 7 deletions npm/eslint-plugin-dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ npm install --save-dev @cypress/eslint-plugin-dev

## Usage

> ⚠️ Currently does **not** support ESLint version 8+
> ⚠️ Currently does **not** support ESLint version 9

For Eslint 8, use version 6.x.x

For Eslint 7 and below, use version 5.x.x

1) install the following `devDependencies`:
```sh
Expand All @@ -30,13 +34,9 @@ eslint-plugin-json-format
@typescript-eslint/eslint-plugin
eslint-plugin-mocha

# if you have coffeescript files
@fellow/eslint-plugin-coffee
babel-eslint

# if you have react/jsx files
eslint-plugin-react
babel-eslint
@babel/eslint-parser
```

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

**requires you to install the following `devDependencies`**:
```sh
babel-eslint
@babel/eslint-parser
eslint-plugin-react
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const ruleComposer = require('eslint-rule-composer')
const arrowBodyStyle = require('eslint/lib/rules/arrow-body-style')
const eslint = require('eslint')
const arrowBodyStyle = new eslint.Linter().getRules().get('arrow-body-style')

module.exports = ruleComposer.filterReports(
arrowBodyStyle,
Expand Down
13 changes: 5 additions & 8 deletions npm/eslint-plugin-dev/lib/custom-rules/no-only.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
let astUtils

try {
astUtils = require('eslint/lib/util/ast-utils')
} catch (e) {
astUtils = require('eslint/lib/shared/ast-utils')
}
// @see https://github.com/eslint/eslint/blob/v8.57.0/lib/shared/ast-utils.js#L12
// This value is not exported anywhere, but hasn't changed in almost a decade.
// we can directly reference the pattern here
const lineBreakPattern = /\r\n|[\r\n\u2028\u2029]/u

module.exports = {
meta: {
Expand All @@ -25,7 +22,7 @@ module.exports = {
const sourceCode = context.getSourceCode()

function getPropertyText (node) {
const lines = sourceCode.getText(node).split(astUtils.LINEBREAK_MATCHER)
const lines = sourceCode.getText(node).split(lineBreakPattern)

return lines[0]
}
Expand Down
28 changes: 4 additions & 24 deletions npm/eslint-plugin-dev/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,25 +238,6 @@ module.exports = {
'@cypress/dev/arrow-body-multiline-braces': 'off',
},
},
{
files: '*.coffee',
parser: '@fellow/eslint-plugin-coffee',
parserOptions: {
parser: 'babel-eslint',
sourceType: 'module',
ecmaVersion: 2018,
},
plugins: [
'@fellow/eslint-plugin-coffee',
],
rules: {
...Object.assign({}, ...Object.keys(baseRules).map((key) => ({ [key]: 'off' }))),
'@fellow/coffee/coffeescript-error': [
'error',
{},
],
},
},
{
files: [
'*.ts',
Expand All @@ -266,17 +247,15 @@ module.exports = {
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
'import',
],
rules: {
'no-undef': 'off',
'no-unused-vars': 'off',
'indent': 'off',
'no-useless-constructor': 'off',
'no-duplicate-imports': 'off',
'import/no-duplicates': 'off',
'@typescript-eslint/no-duplicate-imports': [
'error',
],
'import/no-duplicates': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
Expand Down Expand Up @@ -344,10 +323,11 @@ module.exports = {
env: {
browser: true,
},
parser: 'babel-eslint',
parser: '@babel/eslint-parser',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
requireConfigFile: false,
ecmaFeatures: {
jsx: true,
legacyDecorators: true,
Expand Down
8 changes: 5 additions & 3 deletions npm/eslint-plugin-dev/lib/scripts/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const path = require('path')
const _ = require('lodash')
const EE = require('events')
const sh = require('shelljs')
Expand Down Expand Up @@ -75,12 +76,13 @@ module.exports = {
const filenamesString = sh.ShellString(filenames.join(' '))

const lintCommand = opts.fix ?
`./node_modules/.bin/eslint --color=true --fix '' ${filenamesString}`
: `./node_modules/.bin/eslint --color=true '' ${filenamesString}`
`npx eslint --color=true --fix ${filenamesString}`
: `npx eslint --color=true ${filenamesString}`

// always run command in the root of the monorepo!
return Promise.promisify(sh.exec)(
lintCommand,
{ silent: false, async: true },
{ silent: false, async: true, cwd: path.resolve(__dirname, '../../../../') },
)
.tapCatch(debugTerse)
.return(false)
Expand Down
20 changes: 11 additions & 9 deletions npm/eslint-plugin-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@
"shelljs": "0.8.5"
},
"devDependencies": {
"eslint": "^7.22.0",
"eslint": "^8.56.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-json-format": "^2.0.0",
"eslint-plugin-mocha": "^8.1.0",
"eslint-plugin-mocha": "^8.2.0",
"eslint-plugin-promise": "^4.2.1",
"sinon": "^7.3.2",
"sinon-chai": "^3.3.0"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": ">= 1.11.0",
"@typescript-eslint/parser": ">= 1.11.0",
"babel-eslint": "^7.2.3",
"eslint": ">= 3.2.1",
"@babel/eslint-parser": "^7.0.0",
"@typescript-eslint/eslint-plugin": ">= 7.0.0",
"@typescript-eslint/parser": ">= 7.0.0",
"eslint": "^= 8.0.0",
"eslint-plugin-import": ">= 2.0.0",
"eslint-plugin-json-format": ">= 2.0.0",
"eslint-plugin-mocha": " >= 4.11.0",
"eslint-plugin-react": "^7.22.0"
"eslint-plugin-mocha": " >= 8.0.0",
"eslint-plugin-react": ">= 7.22.0"
},
"bin": {
"lint-changed": "./lib/scripts/lint-changed.js",
Expand All @@ -51,4 +53,4 @@
"eslint",
"eslintplugin"
]
}
}
47 changes: 22 additions & 25 deletions npm/eslint-plugin-dev/test/arrow-body-multiline-braces.spec.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
const path = require('path')
const CLIEngine = require('eslint').CLIEngine
const plugin = require('..')
const eslint = require('eslint')
const plugin = require('../lib')
const _ = require('lodash')
const { expect } = require('chai')

const pluginName = '__plugin__'
const ESLint = eslint.ESLint

function execute (file, options = {}) {
const opts = _.defaultsDeep(options, {
async function execute (file, options = {}) {
const defaultConfig = {
fix: true,
config: {
ignore: false,
useEslintrc: false,
baseConfig: {
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
rules: {
[`${pluginName}/arrow-body-multiline-braces`]: ['error', 'always'],
},
plugins: [pluginName],
},

})

const cli = new CLIEngine({
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
rules: {
[`${pluginName}/arrow-body-multiline-braces`]: ['error', 'always'],
plugins: {
[pluginName]: plugin,
},
...opts,
ignore: false,
useEslintrc: false,
plugins: [pluginName],
})
}
const opts = _.defaultsDeep(options, defaultConfig)

const cli = new ESLint(opts)

cli.addPlugin(pluginName, plugin)
const results = cli.executeOnFiles([path.join(__dirname, file)]).results[0]
const results = await cli.lintFiles([path.join(__dirname, file)])

return results
return results[0]
}

describe('arrow-body-multiline-braces', () => {
it('lint multiline js', async () => {
const filename = './fixtures/multiline.js'
const result = execute(filename, {
const result = await execute(filename, {
fix: true,
})

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

it('lint oneline js', async () => {
const filename = './fixtures/oneline.js'
const result = execute(filename, { fix: false })
const result = await execute(filename, { fix: false })

expect(result.output).not.ok
expect(result.errorCount).eq(0)
Expand Down
42 changes: 20 additions & 22 deletions npm/eslint-plugin-dev/test/no-only.spec.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,45 @@
const path = require('path')
const CLIEngine = require('eslint').CLIEngine
const eslint = require('eslint')
const plugin = require('..')
const _ = require('lodash')
const { expect } = require('chai')

const ruleName = 'no-only'
const pluginName = '__plugin__'
const ESLint = eslint.ESLint

function execute (file, options = {}) {
const opts = _.defaultsDeep(options, {
async function execute (file, options = {}) {
const defaultConfig = {
fix: true,
config: {
ignore: false,
useEslintrc: false,
baseConfig: {
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
rules: {
[`${pluginName}/${ruleName}`]: ['error'],
},
plugins: [pluginName],
},
})

const cli = new CLIEngine({
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
rules: {
[`${pluginName}/${ruleName}`]: ['error'],
plugins: {
[pluginName]: plugin,
},
...opts,
ignore: false,
useEslintrc: false,
plugins: [pluginName],
})
}
const opts = _.defaultsDeep(options, defaultConfig)

const cli = new ESLint(opts)

cli.addPlugin(pluginName, plugin)
const results = cli.executeOnFiles([path.join(__dirname, file)]).results[0]
const results = await cli.lintFiles([path.join(__dirname, file)])

return results
return results[0]
}

describe('no-only', () => {
it('lint js with only', async () => {
const filename = './fixtures/with-only.js'
const result = execute(filename, {
const result = await execute(filename, {
fix: true,
})

Expand Down
Loading
Loading