Skip to content

Commit

Permalink
chore: (for eslint-plugin-dev only is breaking) update eslint-plugin …
Browse files Browse the repository at this point in the history
…dev minimum to eslint 7. Remove support for coffeescript and reconfigured required peer deps
  • Loading branch information
AtofStryker committed Apr 23, 2024
1 parent c5fa260 commit 309ee08
Show file tree
Hide file tree
Showing 25 changed files with 979 additions and 757 deletions.
3 changes: 0 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ module.exports = {
rules: {
'no-duplicate-imports': 'off',
'import/no-duplicates': 'off',
'@typescript-eslint/no-duplicate-imports': [
'error',
],
'prefer-spread': 'off',
'prefer-rest-params': 'off',
'no-useless-constructor': 'off',
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
25 changes: 2 additions & 23 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 @@ -274,9 +255,6 @@ module.exports = {
'no-useless-constructor': 'off',
'no-duplicate-imports': 'off',
'import/no-duplicates': 'off',
'@typescript-eslint/no-duplicate-imports': [
'error',
],
'@typescript-eslint/no-unused-vars': [
'error',
{
Expand Down Expand Up @@ -344,10 +322,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
18 changes: 9 additions & 9 deletions npm/eslint-plugin-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
"shelljs": "0.8.5"
},
"devDependencies": {
"eslint": "^7.22.0",
"eslint": "^8.56.0",
"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-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 +51,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

0 comments on commit 309ee08

Please sign in to comment.