|
| 1 | +import { |
| 2 | + getStyleContexts, |
| 3 | + getCommentDirectivesReporter, |
| 4 | + StyleContext, |
| 5 | + ValidStyleContext, |
| 6 | +} from "../styles/context" |
| 7 | +import type { RuleContext, Rule } from "../types" |
| 8 | +import { |
| 9 | + isPseudoEmptyArguments, |
| 10 | + VGlobalPseudo, |
| 11 | + isVGlobalPseudo, |
| 12 | +} from "../styles/utils/selectors" |
| 13 | + |
| 14 | +declare const module: { |
| 15 | + exports: Rule |
| 16 | +} |
| 17 | + |
| 18 | +module.exports = { |
| 19 | + meta: { |
| 20 | + docs: { |
| 21 | + description: |
| 22 | + "require selector argument to be passed to `::v-global()`.", |
| 23 | + categories: ["vue3-recommended"], |
| 24 | + default: "warn", |
| 25 | + url: |
| 26 | + "https://future-architect.github.io/eslint-plugin-vue-scoped-css/rules/require-v-global-argument.html", |
| 27 | + }, |
| 28 | + fixable: null, |
| 29 | + messages: { |
| 30 | + missingArguments: |
| 31 | + "Need to pass argument to the `::v-global` pseudo-element.", |
| 32 | + }, |
| 33 | + schema: [], |
| 34 | + type: "suggestion", // "problem", |
| 35 | + }, |
| 36 | + create(context: RuleContext) { |
| 37 | + const styles = getStyleContexts(context) |
| 38 | + .filter(StyleContext.isValid) |
| 39 | + .filter((style) => style.scoped) |
| 40 | + if (!styles.length) { |
| 41 | + return {} |
| 42 | + } |
| 43 | + const reporter = getCommentDirectivesReporter(context) |
| 44 | + |
| 45 | + /** |
| 46 | + * Reports the given node |
| 47 | + * @param {ASTNode} node node to report |
| 48 | + */ |
| 49 | + function report(node: VGlobalPseudo) { |
| 50 | + reporter.report({ |
| 51 | + node, |
| 52 | + loc: node.loc, |
| 53 | + messageId: "missingArguments", |
| 54 | + }) |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Verify the style |
| 59 | + */ |
| 60 | + function verify(style: ValidStyleContext) { |
| 61 | + style.traverseSelectorNodes({ |
| 62 | + enterNode(node) { |
| 63 | + if (isVGlobalPseudo(node) && isPseudoEmptyArguments(node)) { |
| 64 | + report(node) |
| 65 | + } |
| 66 | + }, |
| 67 | + }) |
| 68 | + } |
| 69 | + |
| 70 | + return { |
| 71 | + "Program:exit"() { |
| 72 | + for (const style of styles) { |
| 73 | + verify(style) |
| 74 | + } |
| 75 | + }, |
| 76 | + } |
| 77 | + }, |
| 78 | +} |
0 commit comments