@servicetitan/stylelint-config 40.4.0 → 41.0.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;wBAwK9B,OAAO,CAAC,MAAM,CAAC;AAtKpB,kBAsKqB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;wBAyK9B,OAAO,CAAC,MAAM,CAAC;AAvKpB,kBAuKqB"}
package/dist/index.js CHANGED
@@ -5,8 +5,8 @@ module.exports = {
5
5
  'stylelint-prettier/recommended'
6
6
  ],
7
7
  plugins: [
8
- './function-url-no-absolute',
9
- './use-tokens'
8
+ './function-url-no-absolute.js',
9
+ './use-tokens/index.js'
10
10
  ],
11
11
  overrides: [
12
12
  {
@@ -36,7 +36,8 @@ module.exports = {
36
36
  'at-rule-descriptor-no-unknown': null,
37
37
  'at-rule-descriptor-value-no-unknown': null,
38
38
  'at-rule-prelude-no-invalid': null,
39
- 'declaration-property-value-no-unknown': null
39
+ 'declaration-property-value-no-unknown': null,
40
+ 'value-no-invalid': null
40
41
  }
41
42
  }
42
43
  ],
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Config } from 'stylelint';\n\nexport = {\n extends: ['stylelint-config-standard', 'stylelint-prettier/recommended'],\n plugins: ['./function-url-no-absolute', './use-tokens'],\n overrides: [\n {\n files: ['*.scss', '**/*.scss'],\n extends: ['stylelint-config-standard-scss'],\n rules: {\n 'at-rule-descriptor-no-unknown': null,\n 'at-rule-descriptor-value-no-unknown': null,\n 'at-rule-prelude-no-invalid': null,\n 'declaration-property-value-no-unknown': null,\n },\n },\n {\n files: ['*.less', '**/*.less'],\n extends: ['stylelint-config-standard-less'],\n rules: {\n 'at-rule-descriptor-no-unknown': null,\n 'at-rule-descriptor-value-no-unknown': null,\n 'at-rule-prelude-no-invalid': null,\n 'declaration-property-value-no-unknown': null,\n },\n },\n ],\n rules: {\n 'function-no-unknown': [\n true,\n {\n /*\n * these are all less functions at the moment, see the full list here https://lesscss.org/functions/\n * 'extend' and '-' are also added to the list as they are identified as functions thought they are not\n */\n ignoreFunctions: [\n 'extend',\n '-',\n 'if',\n 'boolean',\n 'escape',\n 'e',\n '%',\n 'replace',\n 'length',\n 'extract',\n 'range',\n 'each',\n 'ceil',\n 'floor',\n 'percentage',\n 'round',\n 'sqrt',\n 'abs',\n 'sin',\n 'asin',\n 'cos',\n 'acos',\n 'tan',\n 'atan',\n 'pi',\n 'pow',\n 'mod',\n 'min',\n 'max',\n 'isnumber',\n 'isstring',\n 'iscolor',\n 'iskeyword',\n 'isurl',\n 'ispixel',\n 'isem',\n 'ispercentage',\n 'isunit',\n 'isruleset',\n 'isdefined',\n 'color',\n 'image-size',\n 'image-width',\n 'image-height',\n 'convert',\n 'data-uri',\n 'default',\n 'unit',\n 'get-unit',\n 'svg-gradient',\n 'rgb',\n 'rgba',\n 'argb',\n 'hsl',\n 'hsla',\n 'hsv',\n 'hsva',\n 'hue',\n 'saturation',\n 'lightness',\n 'hsvhue',\n 'hsvsaturation',\n 'hsvvalue',\n 'red',\n 'green',\n 'blue',\n 'alpha',\n 'luma',\n 'luminance',\n 'saturate',\n 'desaturate',\n 'lighten',\n 'darken',\n 'fadein',\n 'fadeout',\n 'fade',\n 'spin',\n 'mix',\n 'tint',\n 'shade',\n 'greyscale',\n 'contrast',\n 'multiply',\n 'screen',\n 'overlay',\n 'softlight',\n 'hardlight',\n 'difference',\n 'exclusion',\n 'average',\n 'negation',\n ],\n },\n ],\n 'selector-pseudo-class-no-unknown': [\n true,\n {\n ignorePseudoClasses: ['global', 'local'],\n },\n ],\n '@servicetitan/function-url-no-absolute': true,\n '@servicetitan/use-tokens': true,\n 'no-invalid-position-at-import-rule': null, // Not supported for LESS/SASS. Enable for CSS when https://github.com/stylelint/stylelint/issues/3128 is implemented.\n 'at-rule-empty-line-before': null, // Require or disallow an empty line before at-rules\n 'alpha-value-notation': null, // Specify percentage or number notation for alpha-values\n 'color-function-notation': null, // Specify modern or legacy notation for color-functions\n 'color-hex-length': null, // Specify short or long notation for hex colors\n 'comment-whitespace-inside': null, // Require or disallow whitespace on the inside of comment markers\n 'custom-property-pattern': null, // Specify a pattern for custom properties\n 'declaration-block-no-shorthand-property-overrides': [true, { severity: 'warning' }], // Disallow shorthand properties that override related longhand properties\n 'declaration-empty-line-before': null, // Require or disallow an empty line before declarations\n 'declaration-block-no-redundant-longhand-properties': null, // Disallow redundant longhand properties within declaration-block\n 'font-family-name-quotes': null, // Require or disallow quotes for font family names\n 'function-url-quotes': null, // Require or disallow quotes for urls.\n 'hue-degree-notation': null, // Specify number or angle notation for degree hues\n 'import-notation': null, // Specify string or URL notation for @import rules\n 'keyframes-name-pattern': null, // Specify a pattern for keyframe names\n 'length-zero-no-unit': null, // Disallow units for zero lengths\n 'media-feature-range-notation': null, // Specify context or prefix notation for media feature ranges\n 'media-query-no-invalid': null, // Disallow invalid media queries (should not turn it on for CSS-like languages, such as Sass or Less)\n 'number-max-precision': null, // Limit the number of decimal places allowed in numbers\n 'property-no-vendor-prefix': null, // Disallow vendor prefixes for properties\n 'rule-empty-line-before': null, // Require or disallow an empty line before rules\n 'shorthand-property-no-redundant-values': null, // Disallow redundant values within shorthand properties\n 'selector-class-pattern': null, // Specify a pattern for class selectors\n 'selector-id-pattern': null, // Specify a pattern for ID selectors\n 'selector-not-notation': null, // Specify simple or complex notation for :not() pseudo-class selectors\n 'selector-pseudo-element-colon-notation': null, // Specify single or double colon notation for applicable pseudo-element selectors\n 'value-keyword-case': null, // Specify lowercase or uppercase for keywords values\n 'value-no-vendor-prefix': null, // Specify lowercase or uppercase for keywords values\n 'color-function-alias-notation': null, // Specify alias notation for color-functions.\n },\n} as Partial<Config>;\n"],"names":["extends","plugins","overrides","files","rules","ignoreFunctions","ignorePseudoClasses","severity"],"mappings":";iBAES;IACLA,SAAS;QAAC;QAA6B;KAAiC;IACxEC,SAAS;QAAC;QAA8B;KAAe;IACvDC,WAAW;QACP;YACIC,OAAO;gBAAC;gBAAU;aAAY;YAC9BH,SAAS;gBAAC;aAAiC;YAC3CI,OAAO;gBACH,iCAAiC;gBACjC,uCAAuC;gBACvC,8BAA8B;gBAC9B,yCAAyC;YAC7C;QACJ;QACA;YACID,OAAO;gBAAC;gBAAU;aAAY;YAC9BH,SAAS;gBAAC;aAAiC;YAC3CI,OAAO;gBACH,iCAAiC;gBACjC,uCAAuC;gBACvC,8BAA8B;gBAC9B,yCAAyC;YAC7C;QACJ;KACH;IACDA,OAAO;QACH,uBAAuB;YACnB;YACA;gBACI;;;iBAGC,GACDC,iBAAiB;oBACb;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;iBACH;YACL;SACH;QACD,oCAAoC;YAChC;YACA;gBACIC,qBAAqB;oBAAC;oBAAU;iBAAQ;YAC5C;SACH;QACD,0CAA0C;QAC1C,4BAA4B;QAC5B,sCAAsC;QACtC,6BAA6B;QAC7B,wBAAwB;QACxB,2BAA2B;QAC3B,oBAAoB;QACpB,6BAA6B;QAC7B,2BAA2B;QAC3B,qDAAqD;YAAC;YAAM;gBAAEC,UAAU;YAAU;SAAE;QACpF,iCAAiC;QACjC,sDAAsD;QACtD,2BAA2B;QAC3B,uBAAuB;QACvB,uBAAuB;QACvB,mBAAmB;QACnB,0BAA0B;QAC1B,uBAAuB;QACvB,gCAAgC;QAChC,0BAA0B;QAC1B,wBAAwB;QACxB,6BAA6B;QAC7B,0BAA0B;QAC1B,0CAA0C;QAC1C,0BAA0B;QAC1B,uBAAuB;QACvB,yBAAyB;QACzB,0CAA0C;QAC1C,sBAAsB;QACtB,0BAA0B;QAC1B,iCAAiC;IACrC;AACJ"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Config } from 'stylelint';\n\nexport = {\n extends: ['stylelint-config-standard', 'stylelint-prettier/recommended'],\n plugins: ['./function-url-no-absolute.js', './use-tokens/index.js'],\n overrides: [\n {\n files: ['*.scss', '**/*.scss'],\n extends: ['stylelint-config-standard-scss'],\n rules: {\n 'at-rule-descriptor-no-unknown': null,\n 'at-rule-descriptor-value-no-unknown': null,\n 'at-rule-prelude-no-invalid': null,\n 'declaration-property-value-no-unknown': null,\n },\n },\n {\n files: ['*.less', '**/*.less'],\n extends: ['stylelint-config-standard-less'],\n rules: {\n 'at-rule-descriptor-no-unknown': null,\n 'at-rule-descriptor-value-no-unknown': null,\n 'at-rule-prelude-no-invalid': null,\n 'declaration-property-value-no-unknown': null,\n 'value-no-invalid': null,\n },\n },\n ],\n rules: {\n 'function-no-unknown': [\n true,\n {\n /*\n * these are all less functions at the moment, see the full list here https://lesscss.org/functions/\n * 'extend' and '-' are also added to the list as they are identified as functions thought they are not\n */\n ignoreFunctions: [\n 'extend',\n '-',\n 'if',\n 'boolean',\n 'escape',\n 'e',\n '%',\n 'replace',\n 'length',\n 'extract',\n 'range',\n 'each',\n 'ceil',\n 'floor',\n 'percentage',\n 'round',\n 'sqrt',\n 'abs',\n 'sin',\n 'asin',\n 'cos',\n 'acos',\n 'tan',\n 'atan',\n 'pi',\n 'pow',\n 'mod',\n 'min',\n 'max',\n 'isnumber',\n 'isstring',\n 'iscolor',\n 'iskeyword',\n 'isurl',\n 'ispixel',\n 'isem',\n 'ispercentage',\n 'isunit',\n 'isruleset',\n 'isdefined',\n 'color',\n 'image-size',\n 'image-width',\n 'image-height',\n 'convert',\n 'data-uri',\n 'default',\n 'unit',\n 'get-unit',\n 'svg-gradient',\n 'rgb',\n 'rgba',\n 'argb',\n 'hsl',\n 'hsla',\n 'hsv',\n 'hsva',\n 'hue',\n 'saturation',\n 'lightness',\n 'hsvhue',\n 'hsvsaturation',\n 'hsvvalue',\n 'red',\n 'green',\n 'blue',\n 'alpha',\n 'luma',\n 'luminance',\n 'saturate',\n 'desaturate',\n 'lighten',\n 'darken',\n 'fadein',\n 'fadeout',\n 'fade',\n 'spin',\n 'mix',\n 'tint',\n 'shade',\n 'greyscale',\n 'contrast',\n 'multiply',\n 'screen',\n 'overlay',\n 'softlight',\n 'hardlight',\n 'difference',\n 'exclusion',\n 'average',\n 'negation',\n ],\n },\n ],\n 'selector-pseudo-class-no-unknown': [\n true,\n {\n ignorePseudoClasses: ['global', 'local'],\n },\n ],\n '@servicetitan/function-url-no-absolute': true,\n '@servicetitan/use-tokens': true,\n 'no-invalid-position-at-import-rule': null, // Not supported for LESS/SASS. Enable for CSS when https://github.com/stylelint/stylelint/issues/3128 is implemented.\n 'at-rule-empty-line-before': null, // Require or disallow an empty line before at-rules\n 'alpha-value-notation': null, // Specify percentage or number notation for alpha-values\n 'color-function-notation': null, // Specify modern or legacy notation for color-functions\n 'color-hex-length': null, // Specify short or long notation for hex colors\n 'comment-whitespace-inside': null, // Require or disallow whitespace on the inside of comment markers\n 'custom-property-pattern': null, // Specify a pattern for custom properties\n 'declaration-block-no-shorthand-property-overrides': [true, { severity: 'warning' }], // Disallow shorthand properties that override related longhand properties\n 'declaration-empty-line-before': null, // Require or disallow an empty line before declarations\n 'declaration-block-no-redundant-longhand-properties': null, // Disallow redundant longhand properties within declaration-block\n 'font-family-name-quotes': null, // Require or disallow quotes for font family names\n 'function-url-quotes': null, // Require or disallow quotes for urls.\n 'hue-degree-notation': null, // Specify number or angle notation for degree hues\n 'import-notation': null, // Specify string or URL notation for @import rules\n 'keyframes-name-pattern': null, // Specify a pattern for keyframe names\n 'length-zero-no-unit': null, // Disallow units for zero lengths\n 'media-feature-range-notation': null, // Specify context or prefix notation for media feature ranges\n 'media-query-no-invalid': null, // Disallow invalid media queries (should not turn it on for CSS-like languages, such as Sass or Less)\n 'number-max-precision': null, // Limit the number of decimal places allowed in numbers\n 'property-no-vendor-prefix': null, // Disallow vendor prefixes for properties\n 'rule-empty-line-before': null, // Require or disallow an empty line before rules\n 'shorthand-property-no-redundant-values': null, // Disallow redundant values within shorthand properties\n 'selector-class-pattern': null, // Specify a pattern for class selectors\n 'selector-id-pattern': null, // Specify a pattern for ID selectors\n 'selector-not-notation': null, // Specify simple or complex notation for :not() pseudo-class selectors\n 'selector-pseudo-element-colon-notation': null, // Specify single or double colon notation for applicable pseudo-element selectors\n 'value-keyword-case': null, // Specify lowercase or uppercase for keywords values\n 'value-no-vendor-prefix': null, // Specify lowercase or uppercase for keywords values\n 'color-function-alias-notation': null, // Specify alias notation for color-functions.\n },\n} as Partial<Config>;\n"],"names":["extends","plugins","overrides","files","rules","ignoreFunctions","ignorePseudoClasses","severity"],"mappings":";iBAES;IACLA,SAAS;QAAC;QAA6B;KAAiC;IACxEC,SAAS;QAAC;QAAiC;KAAwB;IACnEC,WAAW;QACP;YACIC,OAAO;gBAAC;gBAAU;aAAY;YAC9BH,SAAS;gBAAC;aAAiC;YAC3CI,OAAO;gBACH,iCAAiC;gBACjC,uCAAuC;gBACvC,8BAA8B;gBAC9B,yCAAyC;YAC7C;QACJ;QACA;YACID,OAAO;gBAAC;gBAAU;aAAY;YAC9BH,SAAS;gBAAC;aAAiC;YAC3CI,OAAO;gBACH,iCAAiC;gBACjC,uCAAuC;gBACvC,8BAA8B;gBAC9B,yCAAyC;gBACzC,oBAAoB;YACxB;QACJ;KACH;IACDA,OAAO;QACH,uBAAuB;YACnB;YACA;gBACI;;;iBAGC,GACDC,iBAAiB;oBACb;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;oBACA;iBACH;YACL;SACH;QACD,oCAAoC;YAChC;YACA;gBACIC,qBAAqB;oBAAC;oBAAU;iBAAQ;YAC5C;SACH;QACD,0CAA0C;QAC1C,4BAA4B;QAC5B,sCAAsC;QACtC,6BAA6B;QAC7B,wBAAwB;QACxB,2BAA2B;QAC3B,oBAAoB;QACpB,6BAA6B;QAC7B,2BAA2B;QAC3B,qDAAqD;YAAC;YAAM;gBAAEC,UAAU;YAAU;SAAE;QACpF,iCAAiC;QACjC,sDAAsD;QACtD,2BAA2B;QAC3B,uBAAuB;QACvB,uBAAuB;QACvB,mBAAmB;QACnB,0BAA0B;QAC1B,uBAAuB;QACvB,gCAAgC;QAChC,0BAA0B;QAC1B,wBAAwB;QACxB,6BAA6B;QAC7B,0BAA0B;QAC1B,0CAA0C;QAC1C,0BAA0B;QAC1B,uBAAuB;QACvB,yBAAyB;QACzB,0CAA0C;QAC1C,sBAAsB;QACtB,0BAA0B;QAC1B,iCAAiC;IACrC;AACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-tokens.d.ts","sourceRoot":"","sources":["../../src/use-tokens/use-tokens.ts"],"names":[],"mappings":"AAGA,OAAO,SAAmB,MAAM,WAAW,CAAC;;;;qCAyBX,MAAM,SAAS,MAAM;;;AA+HtD,kBAA+E"}
1
+ {"version":3,"file":"use-tokens.d.ts","sourceRoot":"","sources":["../../src/use-tokens/use-tokens.ts"],"names":[],"mappings":"AAGA,OAAO,SAAmB,MAAM,WAAW,CAAC;;;;qCAyBX,MAAM,SAAS,MAAM;;;AAsItD,kBAA+E"}
@@ -73,7 +73,7 @@ const linters = [
73
73
  condition: (property)=>property === 'font-family'
74
74
  }
75
75
  ];
76
- const plugin = (_0, _1, context)=>{
76
+ const plugin = ()=>{
77
77
  return (root, result)=>{
78
78
  var _result_opts_from;
79
79
  const extension = _path.default.extname((_result_opts_from = result.opts.from) !== null && _result_opts_from !== void 0 ? _result_opts_from : '').slice(1).toLowerCase();
@@ -85,7 +85,7 @@ const plugin = (_0, _1, context)=>{
85
85
  decl.value
86
86
  ];
87
87
  let matched = false;
88
- for (const rawValue of values){
88
+ for (const [index, rawValue] of values.entries()){
89
89
  var _ref;
90
90
  const value = (_ref = transformer === null || transformer === void 0 ? void 0 : transformer(rawValue)) !== null && _ref !== void 0 ? _ref : rawValue;
91
91
  const tokens = collection.get(value);
@@ -94,21 +94,22 @@ const plugin = (_0, _1, context)=>{
94
94
  }
95
95
  matched = true;
96
96
  const replacements = getReplacements(tokens, rawValue, extension);
97
- if (context.fix && replacements.length === 1) {
98
- values[values.indexOf(rawValue)] = replacements[0].variable;
99
- } else {
100
- /* When several tokens match, the developer picks one. */ const message = formatMessage(replacements, rawValue);
101
- utils.report({
102
- node: decl,
103
- message,
104
- word: rawValue,
105
- ruleName,
106
- result
107
- });
108
- }
109
- }
110
- if (context.fix) {
111
- decl.value = values.join(' ');
97
+ /* When several tokens match, the developer picks one. */ const fix = replacements.length === 1 ? {
98
+ node: decl,
99
+ apply: ()=>{
100
+ values[index] = replacements[0].variable;
101
+ decl.value = values.join(' ');
102
+ }
103
+ } : undefined;
104
+ const message = formatMessage(replacements, rawValue);
105
+ utils.report({
106
+ node: decl,
107
+ message,
108
+ word: rawValue,
109
+ ruleName,
110
+ result,
111
+ fix
112
+ });
112
113
  }
113
114
  return matched;
114
115
  }
@@ -119,6 +120,10 @@ const plugin = (_0, _1, context)=>{
119
120
  };
120
121
  plugin.ruleName = ruleName;
121
122
  plugin.messages = messages;
123
+ plugin.meta = {
124
+ url: 'https://docs.st.dev/docs/frontend/uikit/eslint-config#use-tokens',
125
+ fixable: true
126
+ };
122
127
  /*
123
128
  * Returns the variables that can replace a literal, negated when the literal is negative, for
124
129
  * example "-16px" becomes "-$spacing-2" in Sass.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/use-tokens/use-tokens.ts"],"sourcesContent":["import Color from 'color';\nimport path from 'path';\nimport type { Declaration } from 'postcss';\nimport stylelint, { Rule } from 'stylelint';\nimport { DESIGN_SYSTEM_SOURCE, Token, TokenSource } from './load-tokens';\nimport {\n borderRadiuses,\n colors,\n fontFamilies,\n fontWeights,\n lineHeights,\n opacities,\n spacings,\n TokenCollection,\n typescales,\n zIndexes,\n} from './values';\n\nconst { createPlugin, utils } = stylelint;\n\n/*\n * Matches spaces outside color functions, so splitting a value on it keeps a color such as\n * rgb(2, 101, 220) whole while still separating the colors inside a gradient.\n */\nconst spaceOutsideColorFunction = / (?<!\\b(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\\([^()]*)/;\n\nconst ruleName = '@servicetitan/use-tokens';\nconst messages = utils.ruleMessages(ruleName, {\n variableExpected: (expected: string, found: string) =>\n `You should use ${expected} instead of \"${found}\".`,\n});\n\ninterface Linter {\n collection: TokenCollection;\n /* Limits the check to matching properties. Without it, every property is checked. */\n condition?: (property: string) => boolean;\n /* Normalizes a value before it's looked up in the collection. */\n transformer?: (value: string) => string;\n /* Looks up each space-separated part of the value. Without it, the whole value is looked up. */\n multipleValues?: boolean;\n}\n\nconst linters: Linter[] = [\n {\n collection: colors,\n transformer: value => {\n try {\n /* Includes alpha, so a translucent color doesn't match an opaque token. */\n return new Color(value).hexa();\n } catch {\n return '';\n }\n },\n multipleValues: true,\n },\n {\n collection: typescales,\n condition: property => property === 'font-size',\n },\n {\n collection: borderRadiuses,\n condition: property => property.startsWith('border-') && property.endsWith('-radius'),\n transformer: value => (value === '0px' ? '0' : value),\n multipleValues: true,\n },\n {\n collection: spacings,\n condition: property => property.startsWith('margin') || property.startsWith('padding'),\n transformer: value => {\n if (value === '0px') {\n return '0';\n }\n return value.startsWith('-') ? value.slice(1) : value;\n },\n multipleValues: true,\n },\n {\n collection: fontWeights,\n condition: property => property === 'font-weight',\n },\n {\n collection: opacities,\n condition: property => property === 'opacity',\n transformer: value => (value.startsWith('0.') ? value.slice(1) : value),\n },\n {\n collection: zIndexes,\n condition: property => property === 'z-index',\n },\n {\n collection: lineHeights,\n condition: property => property === 'line-height',\n },\n {\n collection: fontFamilies,\n condition: property => property === 'font-family',\n },\n];\n\nconst plugin: Rule = (_0, _1, context) => {\n return (root, result) => {\n const extension = path\n .extname(result.opts.from ?? '')\n .slice(1)\n .toLowerCase();\n\n /* Returns whether any part of the declaration's value matched a token. */\n function lint(\n decl: Declaration,\n { collection, condition, transformer, multipleValues }: Linter\n ) {\n if (condition && !condition(decl.prop)) {\n return false;\n }\n\n const values = multipleValues\n ? decl.value.split(spaceOutsideColorFunction)\n : [decl.value];\n\n let matched = false;\n for (const rawValue of values) {\n const value = transformer?.(rawValue) ?? rawValue;\n const tokens = collection.get(value);\n if (!tokens) {\n continue;\n }\n\n matched = true;\n const replacements = getReplacements(tokens, rawValue, extension);\n\n if (context.fix && replacements.length === 1) {\n values[values.indexOf(rawValue)] = replacements[0].variable;\n } else {\n /* When several tokens match, the developer picks one. */\n const message = formatMessage(replacements, rawValue);\n utils.report({ node: decl, message, word: rawValue, ruleName, result });\n }\n }\n\n if (context.fix) {\n decl.value = values.join(' ');\n }\n\n return matched;\n }\n\n root.walkDecls(decl => {\n linters.some(linter => lint(decl, linter));\n });\n };\n};\n\nplugin.ruleName = ruleName;\nplugin.messages = messages;\n\nexport = Object.assign(createPlugin(ruleName, plugin), { ruleName, messages });\n\ninterface Replacement {\n variable: string;\n source: TokenSource;\n}\n\n/*\n * Returns the variables that can replace a literal, negated when the literal is negative, for\n * example \"-16px\" becomes \"-$spacing-2\" in Sass.\n */\nfunction getReplacements(tokens: Token[], rawValue: string, extension: string) {\n const negative = rawValue.startsWith('-');\n\n return tokens.reduce<Replacement[]>((replacements, token) => {\n const plain = convertToVariable(token, extension);\n const variable = negative ? negate(plain, token.source) : plain;\n /*\n * When tokens from different sources match a literal with the same\n * replacement, issue just one replacement that --fix can apply.\n */\n return replacements.some(replacement => replacement.variable === variable)\n ? replacements\n : [...replacements, { variable, source: token.source }];\n }, []);\n}\n\nfunction convertToVariable({ name, customProperty, source }: Token, extension: string) {\n switch (extension) {\n case 'less':\n /* Anvil2 publishes no Less variables. */\n return source === DESIGN_SYSTEM_SOURCE ? `@${name}` : `var(${customProperty})`;\n\n case 'sass':\n case 'scss':\n return `$${name}`;\n\n default:\n return `var(${customProperty})`;\n }\n}\n\n/*\n * A minus sign negates only a variable that holds a plain number, such as a design-system Sass or\n * Less variable. CSS has no unary minus for var(), and Anvil2's Sass variables can hold var(), so\n * those are negated with calc().\n */\nfunction negate(variable: string, source: TokenSource) {\n return source === DESIGN_SYSTEM_SOURCE && !variable.startsWith('var(')\n ? `-${variable}`\n : `calc(-1 * ${variable})`;\n}\n\nfunction formatMessage(replacements: Replacement[], found: string) {\n const choices = replacements\n .map(({ variable, source }) => `\"${variable}\" from \\`${source}\\``)\n .join(' or ');\n return messages.variableExpected(choices, found);\n}\n"],"names":["createPlugin","utils","stylelint","spaceOutsideColorFunction","ruleName","messages","ruleMessages","variableExpected","expected","found","linters","collection","colors","transformer","value","Color","hexa","multipleValues","typescales","condition","property","borderRadiuses","startsWith","endsWith","spacings","slice","fontWeights","opacities","zIndexes","lineHeights","fontFamilies","plugin","_0","_1","context","root","result","extension","path","extname","opts","from","toLowerCase","lint","decl","prop","values","split","matched","rawValue","tokens","get","replacements","getReplacements","fix","length","indexOf","variable","message","formatMessage","report","node","word","join","walkDecls","some","linter","negative","reduce","token","plain","convertToVariable","negate","source","replacement","name","customProperty","DESIGN_SYSTEM_SOURCE","choices","map","Object","assign"],"mappings":";8DAAkB;6DACD;kEAEe;4BACyB;wBAYlD;;;;;;AAEP,MAAM,EAAEA,YAAY,EAAEC,KAAK,EAAE,GAAGC,kBAAS;AAEzC;;;CAGC,GACD,MAAMC,4BAA4B;AAElC,MAAMC,WAAW;AACjB,MAAMC,WAAWJ,MAAMK,YAAY,CAACF,UAAU;IAC1CG,kBAAkB,CAACC,UAAkBC,QACjC,CAAC,eAAe,EAAED,SAAS,aAAa,EAAEC,MAAM,EAAE,CAAC;AAC3D;AAYA,MAAMC,UAAoB;IACtB;QACIC,YAAYC,cAAM;QAClBC,aAAaC,CAAAA;YACT,IAAI;gBACA,yEAAyE,GACzE,OAAO,IAAIC,cAAK,CAACD,OAAOE,IAAI;YAChC,EAAE,eAAM;gBACJ,OAAO;YACX;QACJ;QACAC,gBAAgB;IACpB;IACA;QACIN,YAAYO,kBAAU;QACtBC,WAAWC,CAAAA,WAAYA,aAAa;IACxC;IACA;QACIT,YAAYU,sBAAc;QAC1BF,WAAWC,CAAAA,WAAYA,SAASE,UAAU,CAAC,cAAcF,SAASG,QAAQ,CAAC;QAC3EV,aAAaC,CAAAA,QAAUA,UAAU,QAAQ,MAAMA;QAC/CG,gBAAgB;IACpB;IACA;QACIN,YAAYa,gBAAQ;QACpBL,WAAWC,CAAAA,WAAYA,SAASE,UAAU,CAAC,aAAaF,SAASE,UAAU,CAAC;QAC5ET,a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AiB;IACjF,OAAQA;QACJ,KAAK;YACD,uCAAuC,GACvC,OAAOoC,WAAWI,gCAAoB,GAAG,CAAC,CAAC,EAAEF,MAAM,GAAG,CAAC,IAAI,EAAEC,eAAe,CAAC,CAAC;QAElF,KAAK;QACL,KAAK;YACD,OAAO,CAAC,CAAC,EAAED,MAAM;QAErB;YACI,OAAO,CAAC,IAAI,EAAEC,eAAe,CAAC,CAAC;IACvC;AACJ;AAEA;;;;CAIC,GACD,SAASJ,OAAOf,QAAgB,EAAEgB,MAAmB;IACjD,OAAOA,WAAWI,gCAAoB,IAAI,CAACpB,SAASnC,UAAU,CAAC,UACzD,CAAC,CAAC,EAAEmC,UAAU,GACd,CAAC,UAAU,EAAEA,SAAS,CAAC,CAAC;AAClC;AAEA,SAASE,cAAcP,YAA2B,EAAE3C,KAAa;IAC7D,MAAMqE,UAAU1B,aACX2B,GAAG,CAAC,CAAC,EAAEtB,QAAQ,EAAEgB,MAAM,EAAE,GAAK,CAAC,CAAC,EAAEhB,SAAS,SAAS,EAAEgB,OAAO,EAAE,CAAC,EAChEV,IAAI,CAAC;IACV,OAAO1D,SAASE,gBAAgB,CAACuE,SAASrE;AAC9C;iBA1DSuE,OAAOC,MAAM,CAACjF,aAAaI,UAAU2B,SAAS;IAAE3B;IAAUC;AAAS"}
1
+ {"version":3,"sources":["../../src/use-tokens/use-tokens.ts"],"sourcesContent":["import Color from 'color';\nimport path from 'path';\nimport type { Declaration } from 'postcss';\nimport stylelint, { Rule } from 'stylelint';\nimport { DESIGN_SYSTEM_SOURCE, Token, TokenSource } from './load-tokens';\nimport {\n borderRadiuses,\n colors,\n fontFamilies,\n fontWeights,\n lineHeights,\n opacities,\n spacings,\n TokenCollection,\n typescales,\n zIndexes,\n} from './values';\n\nconst { createPlugin, utils } = stylelint;\n\n/*\n * Matches spaces outside color functions, so splitting a value on it keeps a color such as\n * rgb(2, 101, 220) whole while still separating the colors inside a gradient.\n */\nconst spaceOutsideColorFunction = / (?<!\\b(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)\\([^()]*)/;\n\nconst ruleName = '@servicetitan/use-tokens';\nconst messages = utils.ruleMessages(ruleName, {\n variableExpected: (expected: string, found: string) =>\n `You should use ${expected} instead of \"${found}\".`,\n});\n\ninterface Linter {\n collection: TokenCollection;\n /* Limits the check to matching properties. Without it, every property is checked. */\n condition?: (property: string) => boolean;\n /* Normalizes a value before it's looked up in the collection. */\n transformer?: (value: string) => string;\n /* Looks up each space-separated part of the value. Without it, the whole value is looked up. */\n multipleValues?: boolean;\n}\n\nconst linters: Linter[] = [\n {\n collection: colors,\n transformer: value => {\n try {\n /* Includes alpha, so a translucent color doesn't match an opaque token. */\n return new Color(value).hexa();\n } catch {\n return '';\n }\n },\n multipleValues: true,\n },\n {\n collection: typescales,\n condition: property => property === 'font-size',\n },\n {\n collection: borderRadiuses,\n condition: property => property.startsWith('border-') && property.endsWith('-radius'),\n transformer: value => (value === '0px' ? '0' : value),\n multipleValues: true,\n },\n {\n collection: spacings,\n condition: property => property.startsWith('margin') || property.startsWith('padding'),\n transformer: value => {\n if (value === '0px') {\n return '0';\n }\n return value.startsWith('-') ? value.slice(1) : value;\n },\n multipleValues: true,\n },\n {\n collection: fontWeights,\n condition: property => property === 'font-weight',\n },\n {\n collection: opacities,\n condition: property => property === 'opacity',\n transformer: value => (value.startsWith('0.') ? value.slice(1) : value),\n },\n {\n collection: zIndexes,\n condition: property => property === 'z-index',\n },\n {\n collection: lineHeights,\n condition: property => property === 'line-height',\n },\n {\n collection: fontFamilies,\n condition: property => property === 'font-family',\n },\n];\n\nconst plugin: Rule = () => {\n return (root, result) => {\n const extension = path\n .extname(result.opts.from ?? '')\n .slice(1)\n .toLowerCase();\n\n /* Returns whether any part of the declaration's value matched a token. */\n function lint(\n decl: Declaration,\n { collection, condition, transformer, multipleValues }: Linter\n ) {\n if (condition && !condition(decl.prop)) {\n return false;\n }\n\n const values = multipleValues\n ? decl.value.split(spaceOutsideColorFunction)\n : [decl.value];\n\n let matched = false;\n for (const [index, rawValue] of values.entries()) {\n const value = transformer?.(rawValue) ?? rawValue;\n const tokens = collection.get(value);\n if (!tokens) {\n continue;\n }\n\n matched = true;\n const replacements = getReplacements(tokens, rawValue, extension);\n\n /* When several tokens match, the developer picks one. */\n const fix =\n replacements.length === 1\n ? {\n node: decl,\n apply: () => {\n values[index] = replacements[0].variable;\n decl.value = values.join(' ');\n },\n }\n : undefined;\n\n const message = formatMessage(replacements, rawValue);\n utils.report({ node: decl, message, word: rawValue, ruleName, result, fix });\n }\n\n return matched;\n }\n\n root.walkDecls(decl => {\n linters.some(linter => lint(decl, linter));\n });\n };\n};\n\nplugin.ruleName = ruleName;\nplugin.messages = messages;\nplugin.meta = {\n url: 'https://docs.st.dev/docs/frontend/uikit/eslint-config#use-tokens',\n fixable: true,\n};\n\nexport = Object.assign(createPlugin(ruleName, plugin), { ruleName, messages });\n\ninterface Replacement {\n variable: string;\n source: TokenSource;\n}\n\n/*\n * Returns the variables that can replace a literal, negated when the literal is negative, for\n * example \"-16px\" becomes \"-$spacing-2\" in Sass.\n */\nfunction getReplacements(tokens: Token[], rawValue: string, extension: string) {\n const negative = rawValue.startsWith('-');\n\n return tokens.reduce<Replacement[]>((replacements, token) => {\n const plain = convertToVariable(token, extension);\n const variable = negative ? negate(plain, token.source) : plain;\n /*\n * When tokens from different sources match a literal with the same\n * replacement, issue just one replacement that --fix can apply.\n */\n return replacements.some(replacement => replacement.variable === variable)\n ? replacements\n : [...replacements, { variable, source: token.source }];\n }, []);\n}\n\nfunction convertToVariable({ name, customProperty, source }: Token, extension: string) {\n switch (extension) {\n case 'less':\n /* Anvil2 publishes no Less variables. */\n return source === DESIGN_SYSTEM_SOURCE ? `@${name}` : `var(${customProperty})`;\n\n case 'sass':\n case 'scss':\n return `$${name}`;\n\n default:\n return `var(${customProperty})`;\n }\n}\n\n/*\n * A minus sign negates only a variable that holds a plain number, such as a design-system Sass or\n * Less variable. CSS has no unary minus for var(), and Anvil2's Sass variables can hold var(), so\n * those are negated with calc().\n */\nfunction negate(variable: string, source: TokenSource) {\n return source === DESIGN_SYSTEM_SOURCE && !variable.startsWith('var(')\n ? `-${variable}`\n : `calc(-1 * ${variable})`;\n}\n\nfunction formatMessage(replacements: Replacement[], found: string) {\n const choices = replacements\n .map(({ variable, source }) => `\"${variable}\" from \\`${source}\\``)\n .join(' or ');\n return messages.variableExpected(choices, found);\n}\n"],"names":["createPlugin","utils","stylelint","spaceOutsideColorFunction","ruleName","messages","ruleMessages","variableExpected","expected","found","linters","collection","colors","transformer","value","Color","hexa","multipleValues","typescales","condition","property","borderRadiuses","startsWith","endsWith","spacings","slice","fontWeights","opacities","zIndexes","lineHeights","fontFamilies","plugin","root","result","extension","path","extname","opts","from","toLowerCase","lint","decl","prop","values","split","matched","index","rawValue","entries","tokens","get","replacements","getReplacements","fix","length","node","apply","variable","join","undefined","message","formatMessage","report","word","walkDecls","some","linter","meta","url","fixable","negative","reduce","token","plain","convertToVariable","negate","source","replacement","name","customProperty","DESIGN_SYSTEM_SOURCE","choices","map","Object","assign"],"mappings":";8DAAkB;6DACD;kEAEe;4BACyB;wBAYlD;;;;;;AAEP,MAAM,EAAEA,YAAY,EAAEC,KAAK,EAAE,GAAGC,kBAAS;AAEzC;;;CAGC,GACD,MAAMC,4BAA4B;AAElC,MAAMC,WAAW;AACjB,MAAMC,WAAWJ,MAAMK,YAAY,CAACF,UAAU;IAC1CG,kBAAkB,CAACC,UAAkBC,QACjC,CAAC,eAAe,EAAED,SAAS,aAAa,EAAEC,MAAM,EAAE,CAAC;AAC3D;AAYA,MAAMC,UAAoB;IACtB;QACIC,YAAYC,cAAM;QAClBC,aAAaC,CAAAA;YACT,IAAI;gBACA,yEAAyE,GACzE,OAAO,IAAIC,cAAK,CAACD,OAAOE,IAAI;YAChC,EAAE,eAAM;gBACJ,OAAO;YACX;QACJ;QACAC,gBAAgB;IACpB;IACA;QACIN,YAAYO,kBAAU;QACtBC,WAAWC,CAAAA,WAAYA,aAAa;I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
  "description": "Core Stylelint rule sets for ServiceTitan web projects",
5
5
  "homepage": "https://docs.st.dev/docs/frontend/uikit/eslint-config",
6
6
  "repository": {
@@ -21,21 +21,21 @@
21
21
  ],
22
22
  "dependencies": {
23
23
  "color": "~5.0.3",
24
- "stylelint-config-standard": "~40.0.0",
25
- "stylelint-config-standard-less": "^4.1.0",
26
- "stylelint-config-standard-scss": "^17.0.0",
27
- "stylelint-prettier": "~5.0.3"
24
+ "stylelint-config-standard": "~41.0.0",
25
+ "stylelint-config-standard-less": "^5.0.0",
26
+ "stylelint-config-standard-scss": "^18.0.0",
27
+ "stylelint-prettier": "~5.1.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@servicetitan/anvil2": "^3.19.1",
30
+ "@servicetitan/anvil2": "^3.21.0",
31
31
  "@servicetitan/tokens": "~12.9.0",
32
- "stylelint": "~17.16.0"
32
+ "stylelint": "~18.1.0"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@servicetitan/anvil2": ">=1.9.0",
36
36
  "@servicetitan/tokens": ">=12",
37
37
  "postcss": ">=8",
38
- "stylelint": ">=16"
38
+ "stylelint": ">=18.1.0"
39
39
  },
40
40
  "peerDependenciesMeta": {
41
41
  "@servicetitan/anvil2": {
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@ import { Config } from 'stylelint';
2
2
 
3
3
  export = {
4
4
  extends: ['stylelint-config-standard', 'stylelint-prettier/recommended'],
5
- plugins: ['./function-url-no-absolute', './use-tokens'],
5
+ plugins: ['./function-url-no-absolute.js', './use-tokens/index.js'],
6
6
  overrides: [
7
7
  {
8
8
  files: ['*.scss', '**/*.scss'],
@@ -22,6 +22,7 @@ export = {
22
22
  'at-rule-descriptor-value-no-unknown': null,
23
23
  'at-rule-prelude-no-invalid': null,
24
24
  'declaration-property-value-no-unknown': null,
25
+ 'value-no-invalid': null,
25
26
  },
26
27
  },
27
28
  ],
@@ -97,7 +97,7 @@ const linters: Linter[] = [
97
97
  },
98
98
  ];
99
99
 
100
- const plugin: Rule = (_0, _1, context) => {
100
+ const plugin: Rule = () => {
101
101
  return (root, result) => {
102
102
  const extension = path
103
103
  .extname(result.opts.from ?? '')
@@ -118,7 +118,7 @@ const plugin: Rule = (_0, _1, context) => {
118
118
  : [decl.value];
119
119
 
120
120
  let matched = false;
121
- for (const rawValue of values) {
121
+ for (const [index, rawValue] of values.entries()) {
122
122
  const value = transformer?.(rawValue) ?? rawValue;
123
123
  const tokens = collection.get(value);
124
124
  if (!tokens) {
@@ -128,17 +128,20 @@ const plugin: Rule = (_0, _1, context) => {
128
128
  matched = true;
129
129
  const replacements = getReplacements(tokens, rawValue, extension);
130
130
 
131
- if (context.fix && replacements.length === 1) {
132
- values[values.indexOf(rawValue)] = replacements[0].variable;
133
- } else {
134
- /* When several tokens match, the developer picks one. */
135
- const message = formatMessage(replacements, rawValue);
136
- utils.report({ node: decl, message, word: rawValue, ruleName, result });
137
- }
138
- }
139
-
140
- if (context.fix) {
141
- decl.value = values.join(' ');
131
+ /* When several tokens match, the developer picks one. */
132
+ const fix =
133
+ replacements.length === 1
134
+ ? {
135
+ node: decl,
136
+ apply: () => {
137
+ values[index] = replacements[0].variable;
138
+ decl.value = values.join(' ');
139
+ },
140
+ }
141
+ : undefined;
142
+
143
+ const message = formatMessage(replacements, rawValue);
144
+ utils.report({ node: decl, message, word: rawValue, ruleName, result, fix });
142
145
  }
143
146
 
144
147
  return matched;
@@ -152,6 +155,10 @@ const plugin: Rule = (_0, _1, context) => {
152
155
 
153
156
  plugin.ruleName = ruleName;
154
157
  plugin.messages = messages;
158
+ plugin.meta = {
159
+ url: 'https://docs.st.dev/docs/frontend/uikit/eslint-config#use-tokens',
160
+ fixable: true,
161
+ };
155
162
 
156
163
  export = Object.assign(createPlugin(ruleName, plugin), { ruleName, messages });
157
164