diff --git a/CHANGELOG.md b/CHANGELOG.md index 8776fb9..370fcba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +2019-02-02 v5.0.2 +* Fix support for the --report-unused-disabled-directives option #111 + 2019-02-02 v5.0.1 * Fix compatibility with ESLint 5.13.0 * Update dependencies diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 0c54843..448e2f2 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-html", - "version": "5.0.1", + "version": "5.0.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index cbe8995..cec2f3a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-html", - "version": "5.0.1", + "version": "5.0.2", "description": "A ESLint plugin to lint and fix inline scripts contained in HTML files.", "license": "ISC", "repository": { @@ -23,7 +23,8 @@ "eslint": "^5.13.0", "eslint-config-benoitz-prettier": "^1.1.0", "jest": "^24.0.0", - "prettier": "^1.16.3" + "prettier": "^1.16.3", + "semver": "^5.6.0" }, "scripts": { "validate": "npm run lint && npm run test", diff --git a/src/__tests__/fixtures/inline-disabled-rule.html b/src/__tests__/fixtures/inline-disabled-rule.html new file mode 100644 index 0000000..bef9be6 --- /dev/null +++ b/src/__tests__/fixtures/inline-disabled-rule.html @@ -0,0 +1,4 @@ + diff --git a/src/__tests__/plugin.js b/src/__tests__/plugin.js index 75de622..9be8154 100644 --- a/src/__tests__/plugin.js +++ b/src/__tests__/plugin.js @@ -2,8 +2,15 @@ const path = require("path") const CLIEngine = require("eslint").CLIEngine +const semver = require("semver") +const eslintVersion = require("eslint/package.json").version const plugin = require("..") +function ifVersion(versionSpec, fn, ...args) { + const execFn = semver.satisfies(eslintVersion, versionSpec) ? fn : fn.skip + execFn(...args) +} + function execute(file, baseConfig) { if (!baseConfig) baseConfig = {} @@ -24,6 +31,7 @@ function execute(file, baseConfig) { ignore: false, useEslintrc: false, fix: baseConfig.fix, + reportUnusedDisableDirectives: baseConfig.reportUnusedDisableDirectives, }) cli.addPlugin("html", plugin) const results = cli.executeOnFiles([path.join(__dirname, "fixtures", file)]) @@ -495,6 +503,32 @@ describe("fix", () => { }) }) +ifVersion(">= 4.8.0", describe, "reportUnusedDisableDirectives", () => { + it("reports unused disabled directives", () => { + const messages = execute("inline-disabled-rule.html", { + reportUnusedDisableDirectives: true, + }) + + expect(messages.length).toBe(1) + expect(messages[0].line).toBe(2) + expect(messages[0].column).toBe(3) + expect(messages[0].message).toBe( + "Unused eslint-disable directive (no problems were reported from 'no-eval')." + ) + }) + + it("doesn't report used disabled directives", () => { + const messages = execute("inline-disabled-rule.html", { + reportUnusedDisableDirectives: true, + rules: { + "no-eval": 2, + }, + }) + + expect(messages.length).toBe(0) + }) +}) + describe("html/javascript-mime-types", () => { it("ignores unknown mime types by default", () => { const messages = execute("javascript-mime-types.html") diff --git a/src/index.js b/src/index.js index 4047f8f..64fc71f 100644 --- a/src/index.js +++ b/src/index.js @@ -184,7 +184,11 @@ function patch(Linter) { !ignoreRules && config.rules ), }), - filenameOrOptions, + ignoreRules && typeof filenameOrOptions === "object" + ? Object.assign({}, filenameOrOptions, { + reportUnusedDisableDirectives: false, + }) + : filenameOrOptions, saveState )