@antebudimir/eslint-plugin-vanilla-extract 1.12.0 → 1.14.0

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.
Files changed (34) hide show
  1. package/README.md +90 -14
  2. package/dist/css-rules/no-px-unit/_tests_/no-px-unit.test.d.ts +1 -0
  3. package/dist/css-rules/no-px-unit/_tests_/no-px-unit.test.js +163 -0
  4. package/dist/css-rules/no-px-unit/index.d.ts +2 -0
  5. package/dist/css-rules/no-px-unit/index.js +2 -0
  6. package/dist/css-rules/no-px-unit/no-px-unit-visitor-creator.d.ts +2 -0
  7. package/dist/css-rules/no-px-unit/no-px-unit-visitor-creator.js +55 -0
  8. package/dist/css-rules/no-px-unit/processor.d.ts +3 -0
  9. package/dist/css-rules/no-px-unit/processor.js +93 -0
  10. package/dist/css-rules/no-px-unit/px-unit-processor.d.ts +14 -0
  11. package/dist/css-rules/no-px-unit/px-unit-processor.js +104 -0
  12. package/dist/css-rules/no-px-unit/px-unit-visitor-creator.d.ts +11 -0
  13. package/dist/css-rules/no-px-unit/px-unit-visitor-creator.js +64 -0
  14. package/dist/css-rules/no-px-unit/rule-definition.d.ts +3 -0
  15. package/dist/css-rules/no-px-unit/rule-definition.js +37 -0
  16. package/dist/css-rules/no-px-unit/visitor-creator.d.ts +2 -0
  17. package/dist/css-rules/no-px-unit/visitor-creator.js +55 -0
  18. package/dist/css-rules/prefer-logical-properties/_tests_/prefer-logical-properties.test.d.ts +1 -0
  19. package/dist/css-rules/prefer-logical-properties/_tests_/prefer-logical-properties.test.js +572 -0
  20. package/dist/css-rules/prefer-logical-properties/index.d.ts +2 -0
  21. package/dist/css-rules/prefer-logical-properties/index.js +2 -0
  22. package/dist/css-rules/prefer-logical-properties/logical-properties-processor.d.ts +19 -0
  23. package/dist/css-rules/prefer-logical-properties/logical-properties-processor.js +202 -0
  24. package/dist/css-rules/prefer-logical-properties/logical-properties-visitor-creator.d.ts +14 -0
  25. package/dist/css-rules/prefer-logical-properties/logical-properties-visitor-creator.js +67 -0
  26. package/dist/css-rules/prefer-logical-properties/property-mappings.d.ts +44 -0
  27. package/dist/css-rules/prefer-logical-properties/property-mappings.js +179 -0
  28. package/dist/css-rules/prefer-logical-properties/rule-definition.d.ts +3 -0
  29. package/dist/css-rules/prefer-logical-properties/rule-definition.js +35 -0
  30. package/dist/index.d.ts +2 -0
  31. package/dist/index.js +5 -1
  32. package/dist/sample.css.d.ts +75 -0
  33. package/dist/sample.css.js +540 -0
  34. package/package.json +2 -2
@@ -0,0 +1,64 @@
1
+ import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
2
+ import { processRecipeProperties } from '../shared-utils/recipe-property-processor.js';
3
+ import { ReferenceTracker, createReferenceTrackingVisitor } from '../shared-utils/reference-tracker.js';
4
+ import { processStyleNode } from '../shared-utils/style-node-processor.js';
5
+ import { processNoPxUnitInStyleObject } from './px-unit-processor.js';
6
+ /**
7
+ * Creates ESLint rule visitors for detecting and reporting 'px' units in vanilla-extract style objects.
8
+ * - Tracks calls to vanilla-extract APIs (style, recipe, keyframes, globalStyle, fontFace, etc.).
9
+ * This visitor only orchestrates traversal; the actual reporting and suggestion logic lives in the processor.
10
+ * - Respects the `allow` option (camelCase or kebab-case) by passing it as a Set to the processor.
11
+ *
12
+ * @param context ESLint rule context used to read options and report diagnostics.
13
+ * @returns Rule listener that inspects vanilla-extract call expressions and processes style objects.
14
+ */
15
+ export const createNoPxUnitVisitors = (context) => {
16
+ const tracker = new ReferenceTracker();
17
+ const trackingVisitor = createReferenceTrackingVisitor(tracker);
18
+ const options = context.options?.[0] || {};
19
+ const allowSet = new Set((options.allow ?? []).map((string) => string));
20
+ const process = (context, object) => processNoPxUnitInStyleObject(context, object, allowSet);
21
+ return {
22
+ ...trackingVisitor,
23
+ CallExpression(node) {
24
+ if (node.callee.type !== AST_NODE_TYPES.Identifier)
25
+ return;
26
+ const functionName = node.callee.name;
27
+ if (!tracker.isTrackedFunction(functionName))
28
+ return;
29
+ const originalName = tracker.getOriginalName(functionName);
30
+ if (!originalName)
31
+ return;
32
+ switch (originalName) {
33
+ case 'fontFace':
34
+ if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
35
+ process(context, node.arguments[0]);
36
+ }
37
+ break;
38
+ case 'globalFontFace':
39
+ if (node.arguments.length > 1 && node.arguments[1]?.type === AST_NODE_TYPES.ObjectExpression) {
40
+ process(context, node.arguments[1]);
41
+ }
42
+ break;
43
+ case 'style':
44
+ case 'styleVariants':
45
+ case 'keyframes':
46
+ if (node.arguments.length > 0) {
47
+ processStyleNode(context, node.arguments[0], (context, object) => process(context, object));
48
+ }
49
+ break;
50
+ case 'globalStyle':
51
+ case 'globalKeyframes':
52
+ if (node.arguments.length >= 2) {
53
+ processStyleNode(context, node.arguments[1], (context, object) => process(context, object));
54
+ }
55
+ break;
56
+ case 'recipe':
57
+ if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
58
+ processRecipeProperties(context, node.arguments[0], (context, object) => process(context, object));
59
+ }
60
+ break;
61
+ }
62
+ },
63
+ };
64
+ };
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const noPxUnitRule: Rule.RuleModule;
3
+ export default noPxUnitRule;
@@ -0,0 +1,37 @@
1
+ import { createNoPxUnitVisitors } from './px-unit-visitor-creator.js';
2
+ const noPxUnitRule = {
3
+ meta: {
4
+ type: 'suggestion',
5
+ docs: {
6
+ description: "disallow 'px' units in vanilla-extract style objects, with allowlist option",
7
+ category: 'Best Practices',
8
+ recommended: false,
9
+ },
10
+ // Suggestions are reported from helper modules, so static analysis in this file can’t detect them; disable the false positive.
11
+ // eslint-disable-next-line eslint-plugin/require-meta-has-suggestions
12
+ hasSuggestions: true,
13
+ schema: [
14
+ {
15
+ type: 'object',
16
+ properties: {
17
+ allow: {
18
+ type: 'array',
19
+ items: { type: 'string' },
20
+ uniqueItems: true,
21
+ default: [],
22
+ },
23
+ },
24
+ additionalProperties: false,
25
+ },
26
+ ],
27
+ messages: {
28
+ noPxUnit: "Avoid using 'px' units. Use rem, em, or theme tokens instead.",
29
+ replaceWithRem: "Replace 'px' with 'rem'.",
30
+ removePx: "Remove 'px' unit.",
31
+ },
32
+ },
33
+ create(context) {
34
+ return createNoPxUnitVisitors(context);
35
+ },
36
+ };
37
+ export default noPxUnitRule;
@@ -0,0 +1,2 @@
1
+ import type { Rule } from 'eslint';
2
+ export declare const createNoPxUnitVisitors: (context: Rule.RuleContext) => Rule.RuleListener;
@@ -0,0 +1,55 @@
1
+ import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
2
+ import { processRecipeProperties } from '../shared-utils/recipe-property-processor.js';
3
+ import { ReferenceTracker, createReferenceTrackingVisitor } from '../shared-utils/reference-tracker.js';
4
+ import { processStyleNode } from '../shared-utils/style-node-processor.js';
5
+ import { processNoPxUnitInStyleObject } from './processor.js';
6
+ export const createNoPxUnitVisitors = (context) => {
7
+ const tracker = new ReferenceTracker();
8
+ const trackingVisitor = createReferenceTrackingVisitor(tracker);
9
+ const options = context.options?.[0] || {};
10
+ const allowSet = new Set((options.allow ?? []).map((s) => s));
11
+ const process = (ctx, obj) => processNoPxUnitInStyleObject(ctx, obj, allowSet);
12
+ return {
13
+ ...trackingVisitor,
14
+ CallExpression(node) {
15
+ if (node.callee.type !== AST_NODE_TYPES.Identifier)
16
+ return;
17
+ const functionName = node.callee.name;
18
+ if (!tracker.isTrackedFunction(functionName))
19
+ return;
20
+ const originalName = tracker.getOriginalName(functionName);
21
+ if (!originalName)
22
+ return;
23
+ switch (originalName) {
24
+ case 'fontFace':
25
+ if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
26
+ process(context, node.arguments[0]);
27
+ }
28
+ break;
29
+ case 'globalFontFace':
30
+ if (node.arguments.length > 1 && node.arguments[1]?.type === AST_NODE_TYPES.ObjectExpression) {
31
+ process(context, node.arguments[1]);
32
+ }
33
+ break;
34
+ case 'style':
35
+ case 'styleVariants':
36
+ case 'keyframes':
37
+ if (node.arguments.length > 0) {
38
+ processStyleNode(context, node.arguments[0], (ctx, obj) => process(ctx, obj));
39
+ }
40
+ break;
41
+ case 'globalStyle':
42
+ case 'globalKeyframes':
43
+ if (node.arguments.length >= 2) {
44
+ processStyleNode(context, node.arguments[1], (ctx, obj) => process(ctx, obj));
45
+ }
46
+ break;
47
+ case 'recipe':
48
+ if (node.arguments.length > 0 && node.arguments[0]?.type === AST_NODE_TYPES.ObjectExpression) {
49
+ processRecipeProperties(context, node.arguments[0], (ctx, obj) => process(ctx, obj));
50
+ }
51
+ break;
52
+ }
53
+ },
54
+ };
55
+ };