diff --git a/.eslintrc.yml b/.eslintrc.yml index 1527f90..a63a9fb 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1,14 +1,17 @@ extends: - - plugin:@mysticatea/es2015 - - plugin:@mysticatea/+eslint-plugin + - plugin:@eslint-community/mysticatea/es2015 + - plugin:@eslint-community/mysticatea/+eslint-plugin overrides: - - files: "docs/.vuepress/components/*.vue" - parserOptions: - parser: babel-eslint - - files: "lib/rules/*.js" rules: - "@mysticatea/eslint-plugin/require-meta-docs-url": + "@eslint-community/mysticatea/eslint-plugin/require-meta-docs-url": - error - pattern: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/{{name}}.html" + - files: ["lib/configs.js", "lib/rules.js", "lib/utils.js"] + rules: + "@eslint-community/mysticatea/node/global-require": off + - files: ["tests/**/*.js", "scripts/**/*.js"] + rules: + "@eslint-community/mysticatea/node/global-require": off + "@eslint-community/mysticatea/node/no-sync": off diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 9e1d425..3db2f34 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -42,37 +42,27 @@ jobs: matrix.os }}) strategy: matrix: - eslint: [7] - node: [10, 12.0.0, 12, 14.0.0, 14, 16.0.0, 16, 18.0.0, 18] + eslint: [8] + node: [12.22.0, 12, 14.17.0, 14, 16.0.0, 16, 18.0.0, 18] os: [ubuntu-latest] include: # On other platforms - os: windows-latest - eslint: 7 + eslint: 8 node: 18 - os: macos-latest - eslint: 7 + eslint: 8 node: 18 # On old ESLint versions - - eslint: 6 - node: 18 - os: ubuntu-latest - - eslint: 5 - node: 18 - os: ubuntu-latest - - eslint: 4 + - eslint: 7 node: 18 os: ubuntu-latest - # On old Node.js versions - eslint: 6 - node: 8 - os: ubuntu-latest - - eslint: 5 - node: 6 + node: 18 os: ubuntu-latest # On the minimum supported ESLint/Node.js version - - eslint: 4.19.1 - node: 6.5.0 + - eslint: 6.0.0 + node: 12.22.0 os: ubuntu-latest runs-on: ${{ matrix.os }} steps: @@ -84,31 +74,11 @@ jobs: with: node-version: ${{ matrix.node }} - # - name: 📥 Install dependencies - # run: npm install - - name: 📥 Install Packages for Node v6 - run: | - sudo npm i npm@6.x - ./node_modules/.bin/npm -v - ./node_modules/.bin/npm uninstall vuepress - ./node_modules/.bin/npm install - if: ${{ matrix.node == '6.5.0' || matrix.node == '6' }} - - name: 📥 Uninstall Packages for Node v8 - run: | - npm uninstall vuepress - if: ${{ matrix.node == '8.O.O' || matrix.node == '8' }} - - name: 📥 Install Packages + - name: 📥 Install dependencies run: npm install --legacy-peer-deps - if: ${{ matrix.node != '6.5.0' && matrix.node != '6' }} - # - name: 📥 Install ESLint v${{ matrix.eslint }} - # run: npm install --save-dev eslint@${{ matrix.eslint }} - - name: 📥 Install ESLint v${{ matrix.eslint }} for Node v6 - run: ./node_modules/.bin/npm install --save-dev eslint@${{ matrix.eslint }} - if: ${{ matrix.node == '6.5.0' || matrix.node == '6' }} - name: 📥 Install ESLint v${{ matrix.eslint }} run: npm install --save-dev eslint@${{ matrix.eslint }} - if: ${{ matrix.node != '6.5.0' && matrix.node != '6' }} - name: ▶️ Run test script run: npm run test diff --git a/docs/README.md b/docs/README.md index 9304a37..3fc269e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -26,8 +26,8 @@ npm install --save-dev eslint @eslint-community/eslint-plugin-eslint-comments ``` ::: tip Requirements -- Node.js `6.5.0` or newer. -- ESLint `4.19.1` or newer. +- Node.js `^12.22.0 || ^14.17.0 || >=16.0.0` +- ESLint `^6.0.0 || ^7.0.0` ::: ## 📖 Usage diff --git a/lib/internal/get-linters.js b/lib/internal/get-linters.js index 2482662..c85ecf3 100644 --- a/lib/internal/get-linters.js +++ b/lib/internal/get-linters.js @@ -10,13 +10,14 @@ const needle = `${path.sep}node_modules${path.sep}eslint${path.sep}` module.exports = () => { const eslintPaths = new Set( Object.keys(require.cache) - .filter(id => id.includes(needle)) - .map(id => id.slice(0, id.indexOf(needle) + needle.length)) + .filter((id) => id.includes(needle)) + .map((id) => id.slice(0, id.indexOf(needle) + needle.length)) ) const linters = [] for (const eslintPath of eslintPaths) { try { + // eslint-disable-next-line @eslint-community/mysticatea/node/global-require const linter = require(eslintPath).Linter if (linter) { diff --git a/lib/internal/utils.js b/lib/internal/utils.js index 849bb04..931d483 100644 --- a/lib/internal/utils.js +++ b/lib/internal/utils.js @@ -7,7 +7,8 @@ const escapeStringRegexp = require("escape-string-regexp") const LINE_PATTERN = /[^\r\n\u2028\u2029]*(?:\r\n|[\r\n\u2028\u2029]|$)/gu -const DIRECTIVE_PATTERN = /^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u +const DIRECTIVE_PATTERN = + /^(eslint(?:-env|-enable|-disable(?:(?:-next)?-line)?)?|exported|globals?)(?:\s|$)/u const LINE_COMMENT_PATTERN = /^eslint-disable-(next-)?line$/u module.exports = { diff --git a/lib/rules/disable-enable-pair.js b/lib/rules/disable-enable-pair.js index de3a869..dba7684 100644 --- a/lib/rules/disable-enable-pair.js +++ b/lib/rules/disable-enable-pair.js @@ -14,10 +14,14 @@ module.exports = { "require a `eslint-enable` comment for every `eslint-disable` comment", category: "Best Practices", recommended: true, - url: - "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/disable-enable-pair.html", + url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/disable-enable-pair.html", }, fixable: null, + messages: { + missingRulePair: + "Requires 'eslint-enable' directive for '{{ruleId}}'.", + missingPair: "Requires 'eslint-enable' directive.", + }, schema: [ { type: "object", @@ -57,9 +61,9 @@ module.exports = { context.report({ loc: utils.toRuleIdLocation(area.comment, area.ruleId), - message: area.ruleId - ? "Requires 'eslint-enable' directive for '{{ruleId}}'." - : "Requires 'eslint-enable' directive.", + messageId: area.ruleId + ? "missingRulePair" + : "missingPair", data: area, }) } diff --git a/lib/rules/no-aggregating-enable.js b/lib/rules/no-aggregating-enable.js index 7eff376..6f34616 100644 --- a/lib/rules/no-aggregating-enable.js +++ b/lib/rules/no-aggregating-enable.js @@ -14,10 +14,13 @@ module.exports = { "disallow a `eslint-enable` comment for multiple `eslint-disable` comments", category: "Best Practices", recommended: true, - url: - "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-aggregating-enable.html", + url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-aggregating-enable.html", }, fixable: null, + messages: { + aggregatingEnable: + "This `eslint-enable` comment affects {{count}} `eslint-disable` comments. An `eslint-enable` comment should be for an `eslint-disable` comment.", + }, schema: [], type: "suggestion", }, @@ -35,8 +38,7 @@ module.exports = { if (count >= 2) { context.report({ loc: utils.toForceLocation(comment.loc), - message: - "This `eslint-enable` comment affects {{count}} `eslint-disable` comments. An `eslint-enable` comment should be for an `eslint-disable` comment.", + messageId: "aggregatingEnable", data: { count }, }) } diff --git a/lib/rules/no-duplicate-disable.js b/lib/rules/no-duplicate-disable.js index c6777f8..6afb593 100644 --- a/lib/rules/no-duplicate-disable.js +++ b/lib/rules/no-duplicate-disable.js @@ -13,10 +13,13 @@ module.exports = { description: "disallow duplicate `eslint-disable` comments", category: "Best Practices", recommended: true, - url: - "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-duplicate-disable.html", + url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-duplicate-disable.html", }, fixable: null, + messages: { + duplicateRule: "'{{ruleId}}' rule has been disabled already.", + duplicate: "ESLint rules have been disabled already.", + }, schema: [], type: "problem", }, @@ -30,9 +33,7 @@ module.exports = { for (const item of disabledArea.duplicateDisableDirectives) { context.report({ loc: utils.toRuleIdLocation(item.comment, item.ruleId), - message: item.ruleId - ? "'{{ruleId}}' rule has been disabled already." - : "ESLint rules have been disabled already.", + messageId: item.ruleId ? "duplicateRule" : "duplicate", data: item, }) } diff --git a/lib/rules/no-restricted-disable.js b/lib/rules/no-restricted-disable.js index a20c7af..a620d50 100644 --- a/lib/rules/no-restricted-disable.js +++ b/lib/rules/no-restricted-disable.js @@ -15,10 +15,12 @@ module.exports = { "disallow `eslint-disable` comments about specific rules", category: "Stylistic Issues", recommended: false, - url: - "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-restricted-disable.html", + url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-restricted-disable.html", }, fixable: null, + messages: { + disallow: "Disabling '{{ruleId}}' is not allowed.", + }, schema: { type: "array", items: { type: "string" }, @@ -49,7 +51,7 @@ module.exports = { area.comment, area.ruleId ), - message: "Disabling '{{ruleId}}' is not allowed.", + messageId: "disallow", data: { ruleId: area.ruleId || String(context.options), }, diff --git a/lib/rules/no-unlimited-disable.js b/lib/rules/no-unlimited-disable.js index 39dd22e..942c6d3 100644 --- a/lib/rules/no-unlimited-disable.js +++ b/lib/rules/no-unlimited-disable.js @@ -13,10 +13,13 @@ module.exports = { "disallow `eslint-disable` comments without rule names", category: "Best Practices", recommended: true, - url: - "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unlimited-disable.html", + url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unlimited-disable.html", }, fixable: null, + messages: { + unexpected: + "Unexpected unlimited '{{kind}}' comment. Specify some rule names to disable.", + }, schema: [], type: "suggestion", }, @@ -27,9 +30,8 @@ module.exports = { return { Program() { for (const comment of sourceCode.getAllComments()) { - const directiveComment = utils.parseDirectiveComment( - comment - ) + const directiveComment = + utils.parseDirectiveComment(comment) if (directiveComment == null) { continue } @@ -45,8 +47,7 @@ module.exports = { if (!directiveComment.value) { context.report({ loc: utils.toForceLocation(comment.loc), - message: - "Unexpected unlimited '{{kind}}' comment. Specify some rule names to disable.", + messageId: "unexpected", data: { kind: directiveComment.kind }, }) } diff --git a/lib/rules/no-unused-disable.js b/lib/rules/no-unused-disable.js index f14126a..64d1e40 100644 --- a/lib/rules/no-unused-disable.js +++ b/lib/rules/no-unused-disable.js @@ -13,10 +13,11 @@ module.exports = { description: "disallow unused `eslint-disable` comments", category: "Best Practices", recommended: false, - url: - "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unused-disable.html", + url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unused-disable.html", }, fixable: null, + // eslint-disable-next-line @eslint-community/mysticatea/eslint-plugin/prefer-message-ids + messages: {}, schema: [], type: "problem", }, diff --git a/lib/rules/no-unused-enable.js b/lib/rules/no-unused-enable.js index 88b6a34..c2b6a46 100644 --- a/lib/rules/no-unused-enable.js +++ b/lib/rules/no-unused-enable.js @@ -13,10 +13,14 @@ module.exports = { description: "disallow unused `eslint-enable` comments", category: "Best Practices", recommended: true, - url: - "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unused-enable.html", + url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-unused-enable.html", }, fixable: null, + messages: { + unusedRule: + "'{{ruleId}}' rule is re-enabled but it has not been disabled.", + unused: "ESLint rules are re-enabled but those have not been disabled.", + }, schema: [], type: "problem", }, @@ -30,9 +34,7 @@ module.exports = { for (const item of disabledArea.unusedEnableDirectives) { context.report({ loc: utils.toRuleIdLocation(item.comment, item.ruleId), - message: item.ruleId - ? "'{{ruleId}}' rule is re-enabled but it has not been disabled." - : "ESLint rules are re-enabled but those have not been disabled.", + messageId: item.ruleId ? "unusedRule" : "unused", data: item, }) } diff --git a/lib/rules/no-use.js b/lib/rules/no-use.js index 6ccf308..99f841f 100644 --- a/lib/rules/no-use.js +++ b/lib/rules/no-use.js @@ -12,10 +12,12 @@ module.exports = { description: "disallow ESLint directive-comments", category: "Stylistic Issues", recommended: false, - url: - "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-use.html", + url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/no-use.html", }, fixable: null, + messages: { + disallow: "Unexpected ESLint directive comment.", + }, schema: [ { type: "object", @@ -54,9 +56,8 @@ module.exports = { return { Program() { for (const comment of sourceCode.getAllComments()) { - const directiveComment = utils.parseDirectiveComment( - comment - ) + const directiveComment = + utils.parseDirectiveComment(comment) if (directiveComment == null) { continue } @@ -64,7 +65,7 @@ module.exports = { if (!allowed.has(directiveComment.kind)) { context.report({ loc: utils.toForceLocation(comment.loc), - message: "Unexpected ESLint directive comment.", + messageId: "disallow", }) } } diff --git a/lib/rules/require-description.js b/lib/rules/require-description.js index dad77d7..b751aef 100644 --- a/lib/rules/require-description.js +++ b/lib/rules/require-description.js @@ -13,10 +13,13 @@ module.exports = { "require include descriptions in ESLint directive-comments", category: "Stylistic Issues", recommended: false, - url: - "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/require-description.html", + url: "https://eslint-community.github.io/eslint-plugin-eslint-comments/rules/require-description.html", }, fixable: null, + messages: { + missingDescription: + "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", + }, schema: [ { type: "object", @@ -55,9 +58,8 @@ module.exports = { return { Program() { for (const comment of sourceCode.getAllComments()) { - const directiveComment = utils.parseDirectiveComment( - comment - ) + const directiveComment = + utils.parseDirectiveComment(comment) if (directiveComment == null) { continue } @@ -67,8 +69,7 @@ module.exports = { if (!directiveComment.description) { context.report({ loc: utils.toForceLocation(comment.loc), - message: - "Unexpected undescribed directive comment. Include descriptions to explain why the comment is necessary.", + messageId: "missingDescription", }) } } diff --git a/package.json b/package.json index cc071f4..4c0e090 100644 --- a/package.json +++ b/package.json @@ -3,26 +3,26 @@ "version": "0.0.0-semantically-released", "description": "Additional ESLint rules for ESLint directive comments.", "engines": { - "node": ">=6.5.0" + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, "main": "index.js", "files": [ "lib" ], "peerDependencies": { - "eslint": ">=4.19.1" + "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" }, "dependencies": { "escape-string-regexp": "^1.0.5", "ignore": "^5.2.4" }, "devDependencies": { - "@mysticatea/eslint-plugin": "^13.0.0", + "@eslint-community/eslint-plugin-mysticatea": "^15.3.0", "@types/node": "^14.18.36", "@vuepress/plugin-pwa": "^1.9.8", "babel-eslint": "^10.0.1", "cross-spawn": "^6.0.5", - "eslint": "^7.32.0", + "eslint": "^8.33.0", "eslint4b": "^7.32.0", "fs-extra": "^8.1.0", "mocha": "^6.2.3", @@ -41,7 +41,6 @@ "clean": "rimraf .nyc_output coverage docs/.vuepress/dist", "docs:build": "vuepress build docs", "docs:watch": "vuepress dev docs", - "docs:deploy": "node scripts/deploy", "lint": "eslint lib scripts tests", "test": "nyc mocha \"tests/lib/**/*.js\" --reporter dot --timeout 8000", "coverage": "nyc report --reporter lcov && opener coverage/lcov-report/index.html", diff --git a/scripts/deploy.js b/scripts/deploy.js deleted file mode 100644 index baeb60e..0000000 --- a/scripts/deploy.js +++ /dev/null @@ -1,76 +0,0 @@ -"use strict" - -const { spawn } = require("child_process") -const path = require("path") -const fs = require("fs-extra") -const GH_TOKEN = process.argv[2] -const BUILD_ROOT = path.resolve(__dirname, "../docs/.vuepress/dist") -const DEPLOY_ROOT = path.resolve(__dirname, "..") - -/** - * Execute a command. - * @param {string} command The command to execute. - * @returns {Promise} - */ -function exec(command) { - console.log(`> ${command.replace(GH_TOKEN, "****")}`) - return new Promise((resolve, reject) => { - const cp = spawn(command, [], { shell: true, stdio: "inherit" }) - - cp.on("close", code => { - if (code) { - reject(new Error(`Exited with ${code}.`)) - } else { - resolve() - } - }) - }) -} - -//eslint-disable-next-line @mysticatea/node/no-unsupported-features/es-syntax -;(async () => { - // Checkout. - await exec("git fetch origin gh-pages") - await exec("git checkout gh-pages") - - // Clean. - for (const filename of await fs.readdir(DEPLOY_ROOT)) { - if (filename === "docs" || filename.startsWith(".")) { - continue - } - - console.log(`> rm -rf ${filename}`) - await fs.remove(filename) - } - - // Move. - for (const filename of await fs.readdir(BUILD_ROOT)) { - console.log(`> mv docs/.vuepress/dist/${filename} ${filename}`) - await fs.rename( - path.join(BUILD_ROOT, filename), - path.join(DEPLOY_ROOT, filename) - ) - } - - // Commit. - await exec('git config --global user.email "public@mysticatea.dev"') - await exec('git config --global user.name "Toru Nagashima"') - await exec("git add -A") - let updated = false - try { - await exec('git commit -m "Update: website"') - updated = true - } catch (_error) { - console.log("NO UPDATE") - } - - // Push. - if (updated) { - await exec( - `git push https://mysticatea:${GH_TOKEN}@github.com/eslint-community/eslint-plugin-eslint-comments.git gh-pages:gh-pages` - ) - } -})().catch(error => { - console.error(error.stack) - process.exitCode = 1 -}) diff --git a/scripts/lib/rules.js b/scripts/lib/rules.js index 8b795bf..f9cc745 100644 --- a/scripts/lib/rules.js +++ b/scripts/lib/rules.js @@ -12,8 +12,8 @@ const path = require("path") */ const rules = fs .readdirSync(path.resolve(__dirname, "../../lib/rules")) - .map(fileName => path.basename(fileName, ".js")) - .map(name => { + .map((fileName) => path.basename(fileName, ".js")) + .map((name) => { const meta = require(`../../lib/rules/${name}`).meta return { id: `@eslint-community/eslint-comments/${name}`, @@ -29,10 +29,10 @@ const rules = fs module.exports = rules module.exports.withCategories = ["Best Practices", "Stylistic Issues"].map( - category => ({ + (category) => ({ category, rules: rules.filter( - rule => rule.category === category && !rule.deprecated + (rule) => rule.category === category && !rule.deprecated ), }) ) diff --git a/scripts/lib/utils.js b/scripts/lib/utils.js index 7f668de..9f0e603 100644 --- a/scripts/lib/utils.js +++ b/scripts/lib/utils.js @@ -32,8 +32,8 @@ function createIndex(dirPath) { module.exports = { ${fs .readdirSync(dirPath) - .map(file => path.basename(file, ".js")) - .map(id => `"${id}": require("./${dirName}/${id}"),`) + .map((file) => path.basename(file, ".js")) + .map((id) => `"${id}": require("./${dirName}/${id}"),`) .join("\n ")} } `) diff --git a/scripts/update-docs-headers.js b/scripts/update-docs-headers.js index 4942984..c73170d 100644 --- a/scripts/update-docs-headers.js +++ b/scripts/update-docs-headers.js @@ -19,7 +19,7 @@ for (const rule of rules) { if (rule.deprecated) { headerLines.push( `- ⚠️ This rule was **deprecated** and replaced by ${rule.replacedBy - .map(id => `[${id}](${id}.md) rule`) + .map((id) => `[${id}](${id}.md) rule`) .join(", ")}.` ) } else if (rule.recommended) { diff --git a/scripts/update-recommended-rules.js b/scripts/update-recommended-rules.js index 10400cb..ebaaed6 100644 --- a/scripts/update-recommended-rules.js +++ b/scripts/update-recommended-rules.js @@ -19,8 +19,8 @@ module.exports = { plugins: ["@eslint-community/eslint-comments"], rules: { ${rules - .filter(rule => rule.recommended) - .map(rule => `"${rule.id}": "error",`) + .filter((rule) => rule.recommended) + .map((rule) => `"${rule.id}": "error",`) .join("\n ")} }, } diff --git a/tests/lib/illegal-eslint-disable-line.js b/tests/lib/illegal-eslint-disable-line.js index 47c0d11..c8d6052 100644 --- a/tests/lib/illegal-eslint-disable-line.js +++ b/tests/lib/illegal-eslint-disable-line.js @@ -9,7 +9,7 @@ const path = require("path") const spawn = require("cross-spawn") const rimraf = require("rimraf") const semver = require("semver") -const eslintVersion = require("eslint/package").version +const eslintVersion = require("eslint/package.json").version /** * Run eslint CLI command with a given source code. @@ -35,7 +35,7 @@ function runESLint(code) { const chunks = [] let totalLength = 0 - cp.stdout.on("data", chunk => { + cp.stdout.on("data", (chunk) => { chunks.push(chunk) totalLength += chunk.length }) @@ -63,12 +63,9 @@ describe("multi-line eslint-disable-line comments", () => { "../../node_modules/@eslint-community/eslint-plugin-eslint-comments" ) + fs.mkdirSync(path.dirname(pluginPath), { recursive: true }) if (fs.existsSync(pluginPath)) { rimraf.sync(pluginPath) - } else { - fs.mkdirSync( - path.resolve(__dirname, "../../node_modules/@eslint-community") - ) } fs.symlinkSync(selfPath, pluginPath, "junction") @@ -88,12 +85,12 @@ no-undef*/ `, ]) { it(code, () => - runESLint(code).then(messages => { + runESLint(code).then((messages) => { if (semver.satisfies(eslintVersion, ">=5.0.0")) { assert.strictEqual(messages.length > 0, true) } const normalMessages = messages.filter( - message => message.ruleId != null + (message) => message.ruleId != null ) assert.strictEqual(normalMessages.length, 0) }) diff --git a/tests/lib/rules/disable-enable-pair.js b/tests/lib/rules/disable-enable-pair.js index a64bb67..02e056c 100644 --- a/tests/lib/rules/disable-enable-pair.js +++ b/tests/lib/rules/disable-enable-pair.js @@ -5,7 +5,7 @@ "use strict" const semver = require("semver") -const eslintVersion = require("eslint/package").version +const eslintVersion = require("eslint/package.json").version const RuleTester = require("eslint").RuleTester const rule = require("../../../lib/rules/disable-enable-pair") const tester = new RuleTester() diff --git a/tests/lib/rules/no-aggregating-enable.js b/tests/lib/rules/no-aggregating-enable.js index 4794359..4dccc69 100644 --- a/tests/lib/rules/no-aggregating-enable.js +++ b/tests/lib/rules/no-aggregating-enable.js @@ -5,7 +5,7 @@ "use strict" const semver = require("semver") -const eslintVersion = require("eslint/package").version +const eslintVersion = require("eslint/package.json").version const RuleTester = require("eslint").RuleTester const rule = require("../../../lib/rules/no-aggregating-enable") const tester = new RuleTester() diff --git a/tests/lib/rules/no-duplicate-disable.js b/tests/lib/rules/no-duplicate-disable.js index 5b19f5e..d6e8ce7 100644 --- a/tests/lib/rules/no-duplicate-disable.js +++ b/tests/lib/rules/no-duplicate-disable.js @@ -5,7 +5,7 @@ "use strict" const semver = require("semver") -const eslintVersion = require("eslint/package").version +const eslintVersion = require("eslint/package.json").version const RuleTester = require("eslint").RuleTester const rule = require("../../../lib/rules/no-duplicate-disable") const tester = new RuleTester() diff --git a/tests/lib/rules/no-restricted-disable.js b/tests/lib/rules/no-restricted-disable.js index bee1641..886f13a 100644 --- a/tests/lib/rules/no-restricted-disable.js +++ b/tests/lib/rules/no-restricted-disable.js @@ -5,7 +5,7 @@ "use strict" const semver = require("semver") -const eslintVersion = require("eslint/package").version +const eslintVersion = require("eslint/package.json").version const { Linter, RuleTester } = require("eslint") const rule = require("../../../lib/rules/no-restricted-disable") const coreRules = new Linter().getRules() @@ -138,8 +138,7 @@ tester.run("no-restricted-disable", rule, { }, { - code: - "/*eslint-disable semi, no-extra-semi, semi-style, comma-style*/", + code: "/*eslint-disable semi, no-extra-semi, semi-style, comma-style*/", options: ["*semi*"], errors: [ "Disabling 'semi' is not allowed.", @@ -148,8 +147,7 @@ tester.run("no-restricted-disable", rule, { ], }, { - code: - "/*eslint-disable no-undef, no-redeclare, foo/no-undef, foo/no-redeclare*/", + code: "/*eslint-disable no-undef, no-redeclare, foo/no-undef, foo/no-redeclare*/", options: ["foo/*"], errors: [ "Disabling 'foo/no-undef' is not allowed.", diff --git a/tests/lib/rules/no-unlimited-disable.js b/tests/lib/rules/no-unlimited-disable.js index ade133d..2d6bd21 100644 --- a/tests/lib/rules/no-unlimited-disable.js +++ b/tests/lib/rules/no-unlimited-disable.js @@ -5,7 +5,7 @@ "use strict" const semver = require("semver") -const eslintVersion = require("eslint/package").version +const eslintVersion = require("eslint/package.json").version const RuleTester = require("eslint").RuleTester const rule = require("../../../lib/rules/no-unlimited-disable") const tester = new RuleTester() diff --git a/tests/lib/rules/no-unused-disable.js b/tests/lib/rules/no-unused-disable.js index 2b8ddb8..06d805d 100644 --- a/tests/lib/rules/no-unused-disable.js +++ b/tests/lib/rules/no-unused-disable.js @@ -20,7 +20,7 @@ const path = require("path") const spawn = require("cross-spawn") const rimraf = require("rimraf") const semver = require("semver") -const eslintVersion = require("eslint/package").version +const eslintVersion = require("eslint/package.json").version /** * Run eslint CLI command with a given source code. @@ -52,7 +52,7 @@ function runESLint(code, reportUnusedDisableDirectives = false) { const chunks = [] let totalLength = 0 - cp.stdout.on("data", chunk => { + cp.stdout.on("data", (chunk) => { chunks.push(chunk) totalLength += chunk.length }) @@ -80,15 +80,9 @@ describe("no-unused-disable", () => { "../../../node_modules/@eslint-community/eslint-plugin-eslint-comments" ) + fs.mkdirSync(path.dirname(pluginPath), { recursive: true }) if (fs.existsSync(pluginPath)) { rimraf.sync(pluginPath) - } else { - fs.mkdirSync( - path.resolve( - __dirname, - "../../../node_modules/@eslint-community" - ) - ) } fs.symlinkSync(selfPath, pluginPath, "junction") @@ -177,7 +171,7 @@ var a = b //eslint-disable-line -- description`, : []), ]) { it(code, () => - runESLint(code).then(messages => { + runESLint(code).then((messages) => { assert.strictEqual(messages.length, 0) }) ) @@ -264,46 +258,73 @@ var a = b /*eslint-disable-line no-undef*/`, code: `/*eslint no-undef:off, no-unused-vars:off*/ var a = b //eslint-disable-line no-undef,no-unused-vars`, errors: [ - { - message: - "'no-undef' rule is disabled but never reported.", - line: 2, - column: 33, - endLine: 2, - endColumn: 41, - suggestions: [], - }, - { - message: - "'no-unused-vars' rule is disabled but never reported.", - line: 2, - column: 42, - endLine: 2, - endColumn: 56, - suggestions: [], - }, + ...(semver.satisfies(eslintVersion, ">=8.0.0") + ? [ + { + message: + "'no-undef' rule is disabled but never reported.", + line: 2, + column: 33, + endLine: 2, + endColumn: 41, + suggestions: [], + }, + ] + : [ + { + message: + "'no-undef' rule is disabled but never reported.", + line: 2, + column: 33, + endLine: 2, + endColumn: 41, + suggestions: [], + }, + { + message: + "'no-unused-vars' rule is disabled but never reported.", + line: 2, + column: 42, + endLine: 2, + endColumn: 56, + suggestions: [], + }, + ]), ], }, { code: `/*eslint no-undef:off, no-unused-vars:off*/ var a = b /*eslint-disable-line no-undef,no-unused-vars*/`, errors: [ - { - message: - "'no-undef' rule is disabled but never reported.", - line: 2, - column: 33, - endLine: 2, - endColumn: 41, - }, - { - message: - "'no-unused-vars' rule is disabled but never reported.", - line: 2, - column: 42, - endLine: 2, - endColumn: 56, - }, + ...(semver.satisfies(eslintVersion, ">=8.0.0") + ? [ + { + message: + "'no-undef' rule is disabled but never reported.", + line: 2, + column: 33, + endLine: 2, + endColumn: 41, + }, + ] + : [ + { + message: + "'no-undef' rule is disabled but never reported.", + line: 2, + column: 33, + endLine: 2, + endColumn: 41, + }, + { + message: + "'no-unused-vars' rule is disabled but never reported.", + line: 2, + column: 42, + endLine: 2, + endColumn: 56, + }, + ]), ], }, { @@ -389,24 +410,38 @@ var a = b`, //eslint-disable-next-line no-undef,no-unused-vars var a = b`, errors: [ - { - message: - "'no-undef' rule is disabled but never reported.", - line: 2, - column: 28, - endLine: 2, - endColumn: 36, - suggestions: [], - }, - { - message: - "'no-unused-vars' rule is disabled but never reported.", - line: 2, - column: 37, - endLine: 2, - endColumn: 51, - suggestions: [], - }, + ...(semver.satisfies(eslintVersion, ">=8.0.0") + ? [ + { + message: + "'no-undef' rule is disabled but never reported.", + line: 2, + column: 28, + endLine: 2, + endColumn: 36, + suggestions: [], + }, + ] + : [ + { + message: + "'no-undef' rule is disabled but never reported.", + line: 2, + column: 28, + endLine: 2, + endColumn: 36, + suggestions: [], + }, + { + message: + "'no-unused-vars' rule is disabled but never reported.", + line: 2, + column: 37, + endLine: 2, + endColumn: 51, + suggestions: [], + }, + ]), ], }, { @@ -414,22 +449,35 @@ var a = b`, /*eslint-disable-next-line no-undef,no-unused-vars*/ var a = b`, errors: [ - { - message: - "'no-undef' rule is disabled but never reported.", - line: 2, - column: 28, - endLine: 2, - endColumn: 36, - }, - { - message: - "'no-unused-vars' rule is disabled but never reported.", - line: 2, - column: 37, - endLine: 2, - endColumn: 51, - }, + ...(semver.satisfies(eslintVersion, ">=8.0.0") + ? [ + { + message: + "'no-undef' rule is disabled but never reported.", + line: 2, + column: 28, + endLine: 2, + endColumn: 36, + }, + ] + : [ + { + message: + "'no-undef' rule is disabled but never reported.", + line: 2, + column: 28, + endLine: 2, + endColumn: 36, + }, + { + message: + "'no-unused-vars' rule is disabled but never reported.", + line: 2, + column: 37, + endLine: 2, + endColumn: 51, + }, + ]), ], }, { @@ -485,24 +533,38 @@ var a = b`, /*eslint-disable no-undef,no-unused-vars*/ var a = b`, errors: [ - { - message: - "'no-undef' rule is disabled but never reported.", - line: 2, - column: 18, - endLine: 2, - endColumn: 26, - suggestions: [], - }, - { - message: - "'no-unused-vars' rule is disabled but never reported.", - line: 2, - column: 27, - endLine: 2, - endColumn: 41, - suggestions: [], - }, + ...(semver.satisfies(eslintVersion, ">=8.0.0") + ? [ + { + message: + "'no-undef' rule is disabled but never reported.", + line: 2, + column: 18, + endLine: 2, + endColumn: 26, + suggestions: [], + }, + ] + : [ + { + message: + "'no-undef' rule is disabled but never reported.", + line: 2, + column: 18, + endLine: 2, + endColumn: 26, + suggestions: [], + }, + { + message: + "'no-unused-vars' rule is disabled but never reported.", + line: 2, + column: 27, + endLine: 2, + endColumn: 41, + suggestions: [], + }, + ]), ], }, { @@ -561,24 +623,38 @@ var a = b var a = b /*eslint-enable*/`, errors: [ - { - message: - "'no-undef' rule is disabled but never reported.", - line: 2, - column: 18, - endLine: 2, - endColumn: 26, - suggestions: [], - }, - { - message: - "'no-unused-vars' rule is disabled but never reported.", - line: 2, - column: 27, - endLine: 2, - endColumn: 41, - suggestions: [], - }, + ...(semver.satisfies(eslintVersion, ">=8.0.0") + ? [ + { + message: + "'no-undef' rule is disabled but never reported.", + line: 2, + column: 18, + endLine: 2, + endColumn: 26, + suggestions: [], + }, + ] + : [ + { + message: + "'no-undef' rule is disabled but never reported.", + line: 2, + column: 18, + endLine: 2, + endColumn: 26, + suggestions: [], + }, + { + message: + "'no-unused-vars' rule is disabled but never reported.", + line: 2, + column: 27, + endLine: 2, + endColumn: 41, + suggestions: [], + }, + ]), ], }, { @@ -718,8 +794,7 @@ var a = b ], }, { - code: - "/* eslint new-parens:error*/ /*eslint-disable new-parens*/", + code: "/* eslint new-parens:error*/ /*eslint-disable new-parens*/", errors: [ { message: @@ -856,8 +931,7 @@ var a = b //eslint-disable-line -- description`, // Don't crash even if the source code has a parse error. { - code: - "/*eslint no-undef:error*/\nvar a = b c //eslint-disable-line no-undef", + code: "/*eslint no-undef:error*/\nvar a = b c //eslint-disable-line no-undef", errors: [ { message: "Parsing error: Unexpected token c", @@ -867,7 +941,7 @@ var a = b //eslint-disable-line -- description`, ]) { it(code, () => runESLint(code, reportUnusedDisableDirectives).then( - actualMessages => { + (actualMessages) => { assert.strictEqual(actualMessages.length, errors.length) for (let i = 0; i < errors.length; ++i) { const actual = actualMessages[i] diff --git a/tests/lib/rules/no-unused-enable.js b/tests/lib/rules/no-unused-enable.js index 0430f5c..a0bf459 100644 --- a/tests/lib/rules/no-unused-enable.js +++ b/tests/lib/rules/no-unused-enable.js @@ -5,7 +5,7 @@ "use strict" const semver = require("semver") -const eslintVersion = require("eslint/package").version +const eslintVersion = require("eslint/package.json").version const RuleTester = require("eslint").RuleTester const rule = require("../../../lib/rules/no-unused-enable") const tester = new RuleTester() diff --git a/tests/lib/rules/require-description.js b/tests/lib/rules/require-description.js index 5813dc9..1498637 100644 --- a/tests/lib/rules/require-description.js +++ b/tests/lib/rules/require-description.js @@ -5,7 +5,7 @@ "use strict" const semver = require("semver") -const eslintVersion = require("eslint/package").version +const eslintVersion = require("eslint/package.json").version const RuleTester = require("eslint").RuleTester const rule = require("../../../lib/rules/require-description") const tester = new RuleTester()