Skip to content

Commit

Permalink
fix: skip the plugin if it's not in the config
Browse files Browse the repository at this point in the history
See #262
  • Loading branch information
BenoitZugmeyer committed Apr 9, 2024
1 parent 21a1cc7 commit 16e08d8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/__tests__/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require("path")
const eslint = require("eslint")
const semver = require("semver")
const eslintVersion = require("eslint/package.json").version
require("..")
const eslintPluginHtml = require("..")

function matchVersion(versionSpec) {
return semver.satisfies(eslintVersion, versionSpec, {
Expand All @@ -23,9 +23,12 @@ async function execute(file, options = {}) {
let eslintOptions
if (matchVersion(">= 9")) {
eslintOptions = {
plugins: {
html: require(".."),
},
plugins:
options.usePlugin === false
? {}
: {
html: eslintPluginHtml,
},
baseConfig: {
files: ["**/*.*"],
settings: options.settings || {},
Expand Down Expand Up @@ -148,6 +151,23 @@ it("should extract and remap messages", async () => {
}
})

ifVersion(
">= 9",
it,
"does not apply the plugin if it is not used in the configuration",
async () => {
const messages = await execute("simple.html", {
usePlugin: false,
rules: {
"no-console": "error",
},
})

expect(messages.length).toBe(1)
expect(messages[0].message).toBe("Parsing error: Unexpected token <")
}
)

it("should report correct line numbers with crlf newlines", async () => {
const messages = await execute("crlf-newlines.html")

Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const { createVerifyPatch } = require("./verifyPatch")
const {
createVerifyWithFlatConfigPatch,
} = require("./verifyWithFlatConfigPatch")
const pluginReference = require("./pluginReference")

module.exports = pluginReference

const LINTER_ISPATCHED_PROPERTY_NAME =
"__eslint-plugin-html-verify-function-is-patched"
Expand Down
1 change: 1 addition & 0 deletions src/pluginReference.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {}
5 changes: 5 additions & 0 deletions src/verifyWithFlatConfigPatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const getFileMode = require("./getFileMode")
const extract = require("./extract")
const { verifyWithSharedScopes } = require("./verifyWithSharedScopes")
const { remapMessages } = require("./remapMessages")
const pluginReference = require("./pluginReference")

const PREPARE_RULE_NAME = "__eslint-plugin-html-prepare"
const PREPARE_PLUGIN_NAME = "__eslint-plugin-html-prepare"
Expand All @@ -19,6 +20,10 @@ function createVerifyWithFlatConfigPatch(verifyWithFlatConfig) {
providedOptions
)

if (!Object.values(providedConfig.plugins).includes(pluginReference)) {
return callOriginalVerify()
}

const pluginSettings = getSettings(providedConfig.settings || {})
const mode = getFileMode(pluginSettings, providedOptions.filename)

Expand Down

0 comments on commit 16e08d8

Please sign in to comment.