Skip to content

Commit

Permalink
Fixed false positives when ignoreBEMModifier and captureClassesFromDo…
Browse files Browse the repository at this point in the history
…c were used together in `no-unused-selector` and `require-selector-used-inside`. (#21)
  • Loading branch information
ota-meshi committed Jan 14, 2020
1 parent a435eda commit dd6852e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 6 deletions.
11 changes: 7 additions & 4 deletions .vscode/settings.json
Expand Up @@ -2,18 +2,21 @@
"eslint.validate": [
"javascript",
"javascriptreact",
{ "language": "vue", "autoFix": true },
{ "autoFix": true, "language": "typescript" },
"vue",
"typescript"
],
"typescript.validate.enable": true,
"javascript.validate.enable": false,
"eslint.autoFixOnSave": true,
"eslint.workingDirectories": [
{"directory": "./", "changeProcessCWD": true },
{"directory": "./docs/.vuepress", "changeProcessCWD": true }
],
"vetur.validation.script": false,
"vetur.validation.style": false,
"css.validate": false,
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"editor.codeActionsOnSaveTimeout": 7500
}
6 changes: 6 additions & 0 deletions lib/styles/selectors/query/index.ts
Expand Up @@ -506,6 +506,12 @@ function* genElementsByClassName(
// If the class name is documented, it is considered to match all elements.
yield* elements
return
} else if (removeModifierClassName) {
if (removeModifierClassName.matchString(modClassName)) {
// If the class name is documented, it is considered to match all elements.
yield* elements
return
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-vue-scoped-css",
"version": "0.3.1",
"version": "0.3.2",
"description": "ESLint plugin for Scoped CSS in Vue.js",
"main": "dist/index.js",
"scripts": {
Expand Down
23 changes: 23 additions & 0 deletions tests/lib/rules/no-unused-selector.ts
Expand Up @@ -301,6 +301,29 @@ tester.run("no-unused-selector", rule, {
},
],
},
{
code: `
<template>
<div></div>
</template>
<style scoped>
/* .element - doc. */
.element {
color: green;
}
.element--mod {
color: red;
}
</style>`,
options: [
{
ignoreBEMModifier: true,
captureClassesFromDoc: [
"/(\\.[a-z-]+)(?::[a-z-]+)?\\s+-\\s*[^\\r\\n]+/i",
],
},
],
},
// ignore nodes
`
<template>
Expand Down
23 changes: 23 additions & 0 deletions tests/lib/rules/require-selector-used-inside.ts
Expand Up @@ -262,6 +262,29 @@ tester.run("require-selector-used-inside", rule, {
},
],
},
{
code: `
<template>
<div></div>
</template>
<style scoped>
/* .element - doc. */
.element {
color: green;
}
.element--mod {
color: red;
}
</style>`,
options: [
{
ignoreBEMModifier: true,
captureClassesFromDoc: [
"/(\\.[a-z-]+)(?::[a-z-]+)?\\s+-\\s*[^\\r\\n]+/i",
],
},
],
},
// ignore nodes
`
<template>
Expand Down

0 comments on commit dd6852e

Please sign in to comment.