Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip the plugin if it's not in the config #263

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ UNRELEASED v8.1.0

- Introduce the `html/ignore-tags-without-type` setting #249
- Fix files with unknown extensions being considered as XML #257
- Fix plugin applied even if it's not in the configuration #263
- Update dependencies

2024-02-09 v8.0.0
Expand Down
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