Skip to content

Commit

Permalink
chore: update eslint from version 7 to version 8 (#29355)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
AtofStryker committed Apr 26, 2024
1 parent e2dcf53 commit f14a11a
Show file tree
Hide file tree
Showing 72 changed files with 1,175 additions and 845 deletions.
9 changes: 5 additions & 4 deletions .eslintrc.js
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': [
'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
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
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
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
@@ -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
@@ -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
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
@@ -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
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
@@ -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
@@ -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

5 comments on commit f14a11a

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f14a11a Apr 26, 2024

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.8.2/linux-x64/develop-f14a11aecfbc1e3854daae02b69fb40b4ec801b7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f14a11a Apr 26, 2024

Choose a reason for hiding this comment

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

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.8.2/linux-arm64/develop-f14a11aecfbc1e3854daae02b69fb40b4ec801b7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f14a11a Apr 26, 2024

Choose a reason for hiding this comment

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

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.8.2/win32-x64/develop-f14a11aecfbc1e3854daae02b69fb40b4ec801b7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f14a11a Apr 26, 2024

Choose a reason for hiding this comment

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

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.8.2/darwin-arm64/develop-f14a11aecfbc1e3854daae02b69fb40b4ec801b7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f14a11a Apr 26, 2024

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.8.2/darwin-x64/develop-f14a11aecfbc1e3854daae02b69fb40b4ec801b7/cypress.tgz

Please sign in to comment.