@fluid-topics/ft-eslint 1.3.15 → 1.3.17

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.
package/build/plugin.d.ts CHANGED
@@ -8,6 +8,8 @@ declare const plugin: {
8
8
  "typography-variant": import("eslint").Rule.RuleModule;
9
9
  "interface-no-commas": import("eslint").Rule.RuleModule;
10
10
  "number-property": import("eslint").Rule.RuleModule;
11
+ "lower-case-ft-css-variables": import("eslint").Rule.RuleModule;
12
+ "ft-css-variable-names": import("eslint").Rule.RuleModule;
11
13
  };
12
14
  configs: {
13
15
  recommended: {};
package/build/plugin.js CHANGED
@@ -2,6 +2,8 @@ import { quotedAttributesRule } from "./rules/quoted-attributes";
2
2
  import { typographyVariantRule } from "./rules/typography-variant";
3
3
  import { interfaceNoCommaRule } from "./rules/interface-no-commas";
4
4
  import { numberPropertyRule } from "./rules/number-property";
5
+ import { lowerCaseFtCssVariables } from "./rules/lower-case-ft-css-variables";
6
+ import { ftCssVariableNames } from "./rules/ft-css-variable-names";
5
7
  const plugin = {
6
8
  meta: {
7
9
  name: "eslint-plugin-fluid-topics",
@@ -12,6 +14,8 @@ const plugin = {
12
14
  "typography-variant": typographyVariantRule,
13
15
  "interface-no-commas": interfaceNoCommaRule,
14
16
  "number-property": numberPropertyRule,
17
+ "lower-case-ft-css-variables": lowerCaseFtCssVariables,
18
+ "ft-css-variable-names": ftCssVariableNames,
15
19
  },
16
20
  configs: {
17
21
  recommended: {},
@@ -27,6 +31,8 @@ const flatConfigs = {
27
31
  "ft/typography-variant": "warn",
28
32
  "ft/interface-no-commas": "error",
29
33
  "ft/number-property": "error",
34
+ "ft/lower-case-ft-css-variables": "error",
35
+ "ft/ft-css-variable-names": "error",
30
36
  },
31
37
  },
32
38
  };
@@ -0,0 +1,2 @@
1
+ import { Rule } from "eslint";
2
+ export declare const ftCssVariableNames: Rule.RuleModule;
@@ -0,0 +1,50 @@
1
+ export const ftCssVariableNames = {
2
+ meta: {
3
+ docs: {
4
+ description: "Prevents the usage of --ft- CSS variables names directly.",
5
+ recommended: false,
6
+ },
7
+ schema: [],
8
+ messages: {
9
+ useTypescriptModelsOfVariables: "FT CSS variables must use the typescript models of variables instead of the CSS variables names directly.\n\n"
10
+ + "css`${ FtButtonCssVariables.color.set(`blue`) };` instead of css`--ft-button-color: blue;`\n"
11
+ + "css`padding: ${ FtCardCssVariables.padding };` instead of css`padding: var(--ft-card-padding);`",
12
+ },
13
+ },
14
+ create({ report, sourceCode }) {
15
+ const ftCssVarPattern = /--ft-[a-z0-9-]+/g;
16
+ function reportFtCssVariableNames(rawValue, sourceLocation, offset) {
17
+ const ftCssVarMatch = rawValue.matchAll(ftCssVarPattern);
18
+ for (const match of ftCssVarMatch) {
19
+ const cssVar = match[0];
20
+ const quasiIndex = sourceCode.getIndexFromLoc(sourceLocation.start);
21
+ const start = quasiIndex + match.index + offset;
22
+ const end = quasiIndex + match.index + cssVar.length + offset;
23
+ report({
24
+ messageId: "useTypescriptModelsOfVariables",
25
+ loc: {
26
+ start: sourceCode.getLocFromIndex(start),
27
+ end: sourceCode.getLocFromIndex(end),
28
+ },
29
+ });
30
+ }
31
+ }
32
+ return {
33
+ TemplateLiteral: (node) => {
34
+ for (const quasi of node.quasis) {
35
+ reportFtCssVariableNames(quasi.value.raw, quasi.loc, 1);
36
+ }
37
+ },
38
+ TaggedTemplateExpression: (node) => {
39
+ if (node.type !== "TaggedTemplateExpression"
40
+ || node.tag.type !== "Identifier"
41
+ || (node.tag.name !== "css" && node.tag.name !== "html")) {
42
+ return;
43
+ }
44
+ for (const quasi of node.quasi.quasis) {
45
+ reportFtCssVariableNames(quasi.value.raw, quasi.loc, 1);
46
+ }
47
+ },
48
+ };
49
+ },
50
+ };
@@ -0,0 +1,2 @@
1
+ import { Rule } from "eslint";
2
+ export declare const lowerCaseFtCssVariables: Rule.RuleModule;
@@ -0,0 +1,58 @@
1
+ export const lowerCaseFtCssVariables = {
2
+ meta: {
3
+ docs: {
4
+ description: "Enforces the format of --ft- CSS variables to lower case.",
5
+ recommended: false,
6
+ },
7
+ fixable: "code",
8
+ schema: [],
9
+ messages: {
10
+ upperCaseCssVariable: "FT CSS variables must be lower case.",
11
+ },
12
+ },
13
+ create({ report, sourceCode }) {
14
+ const ftCssVarPattern = /--ft-[a-zA-Z0-9-]+/g;
15
+ function reportUpperCaseCssVariables(rawValue, sourceLocation, offset) {
16
+ const ftCssVarMatch = rawValue.matchAll(ftCssVarPattern);
17
+ for (const match of ftCssVarMatch) {
18
+ const cssVar = match[0];
19
+ if (cssVar.match(/[A-Z]/)) {
20
+ const quasiIndex = sourceCode.getIndexFromLoc(sourceLocation.start);
21
+ const start = quasiIndex + match.index + offset;
22
+ const end = quasiIndex + match.index + cssVar.length + offset;
23
+ report({
24
+ messageId: "upperCaseCssVariable",
25
+ loc: {
26
+ start: sourceCode.getLocFromIndex(start),
27
+ end: sourceCode.getLocFromIndex(end),
28
+ },
29
+ fix: (fixer) => [
30
+ fixer.replaceTextRange([start, end], cssVar.toLowerCase()),
31
+ ],
32
+ });
33
+ }
34
+ }
35
+ }
36
+ return {
37
+ TemplateLiteral: (node) => {
38
+ for (const quasi of node.quasis) {
39
+ reportUpperCaseCssVariables(quasi.value.raw, quasi.loc, 1);
40
+ }
41
+ },
42
+ TaggedTemplateExpression: (node) => {
43
+ if (node.type !== "TaggedTemplateExpression"
44
+ || node.tag.type !== "Identifier"
45
+ || (node.tag.name !== "css" && node.tag.name !== "html")) {
46
+ return;
47
+ }
48
+ for (const quasi of node.quasi.quasis) {
49
+ reportUpperCaseCssVariables(quasi.value.raw, quasi.loc, 1);
50
+ }
51
+ },
52
+ Literal: (node) => {
53
+ var _a;
54
+ reportUpperCaseCssVariables((_a = node.raw) !== null && _a !== void 0 ? _a : "", node.loc, 0);
55
+ },
56
+ };
57
+ },
58
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-eslint",
3
- "version": "1.3.15",
3
+ "version": "1.3.17",
4
4
  "description": "ESlint rules for web components",
5
5
  "keywords": [
6
6
  "Lit"
@@ -21,5 +21,5 @@
21
21
  "dependencies": {
22
22
  "lit": "3.1.0"
23
23
  },
24
- "gitHead": "5aa2861244264a93f9ce941c3541191eb22a4650"
24
+ "gitHead": "ca55c7b44d386d960ceb68323361ce0ab3aefaa8"
25
25
  }