@master/eslint-plugin-css 2.0.0-rc.79 → 2.0.0-rc.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@ import create_rule_default from "../create-rule.js";
2
2
  import defineVisitors from "../utils/define-visitors.js";
3
3
  import resolveContext from "../utils/resolve-context.js";
4
4
  import reportLintDiagnostics from "../utils/report-lint-diagnostics.js";
5
+ import defineSourceVisitors, { shouldUseSourceVisitors } from "../utils/define-source-visitors.js";
5
6
  import { createConflictingClassesReport } from "@master/css-lint";
6
7
  //#region src/rules/no-conflicting-classes.ts
7
8
  var no_conflicting_classes_default = create_rule_default({
@@ -19,6 +20,11 @@ var no_conflicting_classes_default = create_rule_default({
19
20
  defaultOptions: [],
20
21
  create(context) {
21
22
  const { settings, css } = resolveContext(context);
23
+ if (shouldUseSourceVisitors(context)) return defineSourceVisitors({
24
+ context,
25
+ css,
26
+ ruleId: "no-conflicting-classes"
27
+ });
22
28
  return defineVisitors({
23
29
  context,
24
30
  settings
@@ -2,6 +2,7 @@ import create_rule_default from "../create-rule.js";
2
2
  import defineVisitors from "../utils/define-visitors.js";
3
3
  import resolveContext from "../utils/resolve-context.js";
4
4
  import reportLintDiagnostics from "../utils/report-lint-diagnostics.js";
5
+ import defineSourceVisitors, { shouldUseSourceVisitors } from "../utils/define-source-visitors.js";
5
6
  import { noInvalidClassesOptionsSchema } from "../settings-schema.js";
6
7
  import { createInvalidClassesReport } from "@master/css-lint";
7
8
  //#region src/rules/no-invalid-classes.ts
@@ -20,6 +21,12 @@ var no_invalid_classes_default = create_rule_default({
20
21
  defaultOptions: [],
21
22
  create: function(context) {
22
23
  const { options, settings, css } = resolveContext(context);
24
+ if (shouldUseSourceVisitors(context)) return defineSourceVisitors({
25
+ context,
26
+ css,
27
+ ruleId: "no-invalid-classes",
28
+ ruleOptions: { disallowUnknownClass: options.disallowUnknownClass }
29
+ });
23
30
  return defineVisitors({
24
31
  context,
25
32
  settings
@@ -2,6 +2,7 @@ import create_rule_default from "../create-rule.js";
2
2
  import defineVisitors from "../utils/define-visitors.js";
3
3
  import resolveContext from "../utils/resolve-context.js";
4
4
  import reportLintDiagnostics from "../utils/report-lint-diagnostics.js";
5
+ import defineSourceVisitors, { shouldUseSourceVisitors } from "../utils/define-source-visitors.js";
5
6
  import { createUnapprovedRawValueClassesReport } from "@master/css-lint";
6
7
  //#region src/rules/no-unapproved-raw-values.ts
7
8
  var no_unapproved_raw_values_default = create_rule_default({
@@ -37,6 +38,12 @@ var no_unapproved_raw_values_default = create_rule_default({
37
38
  create(context) {
38
39
  const { settings, css } = resolveContext(context);
39
40
  const options = context.options[0] || {};
41
+ if (shouldUseSourceVisitors(context)) return defineSourceVisitors({
42
+ context,
43
+ css,
44
+ ruleId: "no-unapproved-raw-values",
45
+ ruleOptions: options
46
+ });
40
47
  return defineVisitors({
41
48
  context,
42
49
  settings
@@ -2,6 +2,7 @@ import create_rule_default from "../create-rule.js";
2
2
  import defineVisitors from "../utils/define-visitors.js";
3
3
  import resolveContext from "../utils/resolve-context.js";
4
4
  import reportLintDiagnostics from "../utils/report-lint-diagnostics.js";
5
+ import defineSourceVisitors, { shouldUseSourceVisitors } from "../utils/define-source-visitors.js";
5
6
  import resolveComposeDirectiveClassNodes from "../utils/resolve-compose-directive-class-nodes.js";
6
7
  import { createCanonicalClassesReport, createCanonicalComposeDirectiveReport, defaultCanonicalClassNameOptions } from "@master/css-lint";
7
8
  //#region src/rules/prefer-canonical-classes.ts
@@ -35,6 +36,12 @@ var prefer_canonical_classes_default = create_rule_default({
35
36
  ...defaultCanonicalClassNameOptions,
36
37
  ...context.options[0] || {}
37
38
  };
39
+ if (shouldUseSourceVisitors(context)) return defineSourceVisitors({
40
+ context,
41
+ css,
42
+ ruleId: "prefer-canonical-classes",
43
+ ruleOptions: options
44
+ });
38
45
  const reportCanonicalClassList = (node, { raw, start, end, unescape, classNodes, classValues }) => {
39
46
  reportLintDiagnostics(context, node, {
40
47
  raw,
@@ -2,6 +2,7 @@ import create_rule_default from "../create-rule.js";
2
2
  import defineVisitors from "../utils/define-visitors.js";
3
3
  import resolveContext from "../utils/resolve-context.js";
4
4
  import reportLintDiagnostics from "../utils/report-lint-diagnostics.js";
5
+ import defineSourceVisitors, { shouldUseSourceVisitors } from "../utils/define-source-visitors.js";
5
6
  import { createSortClassesReport } from "@master/css-lint";
6
7
  //#region src/rules/sort-classes.ts
7
8
  var sort_classes_default = create_rule_default({
@@ -16,6 +17,11 @@ var sort_classes_default = create_rule_default({
16
17
  defaultOptions: [],
17
18
  create: function(context) {
18
19
  const { settings, css } = resolveContext(context);
20
+ if (shouldUseSourceVisitors(context)) return defineSourceVisitors({
21
+ context,
22
+ css,
23
+ ruleId: "sort-classes"
24
+ });
19
25
  return defineVisitors({
20
26
  context,
21
27
  settings
@@ -0,0 +1,21 @@
1
+ import { MasterCSSLintContentRuleOptions, MasterCSSLintRuleId } from "@master/css-lint";
2
+ import { MasterCSS } from "@master/css-engine";
3
+ import { RuleContext, RuleListener } from "@typescript-eslint/utils/ts-eslint";
4
+
5
+ //#region src/utils/define-source-visitors.d.ts
6
+ type SourceRuleOptions = MasterCSSLintContentRuleOptions[keyof MasterCSSLintContentRuleOptions];
7
+ interface DefineSourceVisitorsOptions {
8
+ context: RuleContext<any, any[]>;
9
+ css: MasterCSS;
10
+ ruleId: MasterCSSLintRuleId;
11
+ ruleOptions?: SourceRuleOptions;
12
+ }
13
+ declare function shouldUseSourceVisitors(context: RuleContext<any, any[]>): boolean;
14
+ declare function defineSourceVisitors({
15
+ context,
16
+ css,
17
+ ruleId,
18
+ ruleOptions
19
+ }: DefineSourceVisitorsOptions): RuleListener;
20
+ //#endregion
21
+ export { defineSourceVisitors as default, shouldUseSourceVisitors };
@@ -0,0 +1,52 @@
1
+ import { messageIdByCode, stringifyLintDiagnosticData } from "./report-lint-diagnostics.js";
2
+ import { lintMasterCSSContent, masterCSSLintRuleIds } from "@master/css-lint";
3
+ //#region src/utils/define-source-visitors.ts
4
+ const SOURCE_LINT_FILE_RE = /\.mdx$/i;
5
+ function shouldUseSourceVisitors(context) {
6
+ const filename = context.physicalFilename || context.filename;
7
+ return typeof filename === "string" && SOURCE_LINT_FILE_RE.test(filename);
8
+ }
9
+ function getFilename(context) {
10
+ return context.physicalFilename || context.filename || "source.mdx";
11
+ }
12
+ function createSingleRuleSet(ruleId) {
13
+ return Object.fromEntries(masterCSSLintRuleIds.map((eachRuleId) => [eachRuleId, eachRuleId === ruleId]));
14
+ }
15
+ function createRuleOptions(ruleId, ruleOptions) {
16
+ return ruleOptions ? { [ruleId]: ruleOptions } : void 0;
17
+ }
18
+ function reportSourceDiagnostic(context, node, diagnostic) {
19
+ const { sourceCode } = context;
20
+ const messageId = messageIdByCode[diagnostic.code];
21
+ const fix = diagnostic.fixes?.[0];
22
+ const descriptor = {
23
+ node,
24
+ loc: {
25
+ start: sourceCode.getLocFromIndex(diagnostic.range.start),
26
+ end: sourceCode.getLocFromIndex(diagnostic.range.end)
27
+ },
28
+ ...messageId ? {
29
+ messageId,
30
+ data: stringifyLintDiagnosticData(diagnostic.data || { message: diagnostic.message })
31
+ } : { message: diagnostic.message }
32
+ };
33
+ if (fix) descriptor.fix = (fixer) => fixer.replaceTextRange([fix.range.start, fix.range.end], fix.text);
34
+ context.report(descriptor);
35
+ }
36
+ function defineSourceVisitors({ context, css, ruleId, ruleOptions }) {
37
+ return { Program(node) {
38
+ const result = lintMasterCSSContent({
39
+ content: context.sourceCode.getText(),
40
+ filePath: getFilename(context),
41
+ css,
42
+ rules: createSingleRuleSet(ruleId),
43
+ ruleOptions: createRuleOptions(ruleId, ruleOptions)
44
+ });
45
+ for (const diagnostic of result.diagnostics) {
46
+ if (diagnostic.ruleId !== ruleId) continue;
47
+ reportSourceDiagnostic(context, node, diagnostic);
48
+ }
49
+ } };
50
+ }
51
+ //#endregion
52
+ export { defineSourceVisitors as default, shouldUseSourceVisitors };
@@ -11,6 +11,10 @@ interface ReportLintDiagnosticsOptions {
11
11
  text: string;
12
12
  } | undefined;
13
13
  }
14
+ declare const messageIdByCode: Record<string, string>;
15
+ declare function stringifyLintDiagnosticData(data?: MasterCSSLintDiagnostic['data']): {
16
+ [k: string]: string;
17
+ };
14
18
  declare function reportLintDiagnostics(context: RuleContext<any, any[]>, node: TSESTree.Node, resolved: ResolvedClassNode, diagnostics: MasterCSSLintDiagnostic[], options?: ReportLintDiagnosticsOptions): void;
15
19
  //#endregion
16
- export { reportLintDiagnostics as default };
20
+ export { reportLintDiagnostics as default, messageIdByCode, stringifyLintDiagnosticData };
@@ -10,7 +10,7 @@ const messageIdByCode = {
10
10
  "prefer-variant-block": "preferClass",
11
11
  "unapproved-raw-value": "unapprovedRawValue"
12
12
  };
13
- function stringifyData(data = {}) {
13
+ function stringifyLintDiagnosticData(data = {}) {
14
14
  return Object.fromEntries(Object.entries(data).filter(([, value]) => value !== void 0).map(([key, value]) => [key, Array.isArray(value) ? value.join(", ") : String(value)]));
15
15
  }
16
16
  function defaultFix(resolved, fix) {
@@ -35,7 +35,7 @@ function reportLintDiagnostics(context, node, resolved, diagnostics, options = {
35
35
  },
36
36
  ...messageId ? {
37
37
  messageId,
38
- data: stringifyData(diagnostic.data || { message: diagnostic.message })
38
+ data: stringifyLintDiagnosticData(diagnostic.data || { message: diagnostic.message })
39
39
  } : { message: diagnostic.message }
40
40
  };
41
41
  if (fix) descriptor.fix = (fixer) => fixer.replaceTextRange(fix.range, fix.text);
@@ -43,4 +43,4 @@ function reportLintDiagnostics(context, node, resolved, diagnostics, options = {
43
43
  }
44
44
  }
45
45
  //#endregion
46
- export { reportLintDiagnostics as default };
46
+ export { reportLintDiagnostics as default, messageIdByCode, stringifyLintDiagnosticData };
package/package.json CHANGED
@@ -47,12 +47,12 @@
47
47
  "dependencies": {
48
48
  "@typescript-eslint/utils": "^8.61.1",
49
49
  "typescript-eslint": "^8.61.1",
50
- "@master/css": "^2.0.0-rc.79",
51
- "@master/css-lexer": "^2.0.0-rc.79",
52
- "@master/css-project": "^2.0.0-rc.79",
53
- "@master/css-preset": "^2.0.0-rc.79",
54
- "@master/css-validator": "^2.0.0-rc.79",
55
- "@master/css-lint": "^2.0.0-rc.79"
50
+ "@master/css": "^2.0.0-rc.80",
51
+ "@master/css-lexer": "^2.0.0-rc.80",
52
+ "@master/css-lint": "^2.0.0-rc.80",
53
+ "@master/css-preset": "^2.0.0-rc.80",
54
+ "@master/css-project": "^2.0.0-rc.80",
55
+ "@master/css-validator": "^2.0.0-rc.80"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@angular-eslint/template-parser": "^21.4.0",
@@ -65,9 +65,9 @@
65
65
  "svelte-eslint-parser": "^1.8.0",
66
66
  "ts-node": "^10.9.2",
67
67
  "vue-eslint-parser": "^10.4.1",
68
- "@master/css-schema": "^2.0.0-rc.79"
68
+ "@master/css-schema": "^2.0.0-rc.80"
69
69
  },
70
- "version": "2.0.0-rc.79",
70
+ "version": "2.0.0-rc.80",
71
71
  "scripts": {
72
72
  "build": "tsdown --config ../../shared/tsdown-package.config.ts",
73
73
  "dev": "tsdown --config ../../shared/tsdown-package.config.ts --watch",