@plumeria/eslint-plugin 10.1.3 → 10.2.1

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/README.md CHANGED
@@ -11,6 +11,7 @@ The `plugin:@plumeria/recommended` config enables the following:
11
11
  - `@plumeria/no-combinator`: **error**
12
12
  - `@plumeria/no-destructure`: **error**
13
13
  - `@plumeria/no-inner-call`: **error**
14
+ - `@plumeria/no-unknown-css-properties`: **error**
14
15
  - `@plumeria/no-unused-keys`: **warn**
15
16
  - `@plumeria/sort-properties`: **warn**
16
17
  - `@plumeria/format-properties`: **warn**
@@ -35,11 +36,15 @@ Disallow combinators `>`, `+`, `~` and descendant combinator (space) unless insi
35
36
 
36
37
  ### no-destructure
37
38
 
38
- Disallow destructuring `css.create` and `css.props`, etc.
39
+ Disallow destructuring APIs.
39
40
 
40
41
  ### no-inner-call
41
42
 
42
- Disallow calling `css.create`, etc. inside functions.
43
+ Disallow calling APIs inside functions.
44
+
45
+ ### no-unknown-css-properties
46
+
47
+ Disallow unknown CSS properties in camelCase within `css.create`, `css.keyframes`, and `css.viewTransition`.
43
48
 
44
49
  ### no-unused-keys
45
50
 
package/dist/index.js CHANGED
@@ -9,11 +9,13 @@ const sort_properties_1 = require("./rules/sort-properties");
9
9
  const format_properties_1 = require("./rules/format-properties");
10
10
  const validate_values_1 = require("./rules/validate-values");
11
11
  const style_name_requires_import_1 = require("./rules/style-name-requires-import");
12
+ const no_unknown_css_properties_1 = require("./rules/no-unknown-css-properties");
12
13
  const rules = {
13
14
  'style-name-requires-import': style_name_requires_import_1.styleNameRequiresImport,
14
15
  'no-combinator': no_combinator_1.noCombinator,
15
16
  'no-destructure': no_destructure_1.noDestructure,
16
17
  'no-inner-call': no_inner_call_1.noInnerCall,
18
+ 'no-unknown-css-properties': no_unknown_css_properties_1.noUnknownCssProperties,
17
19
  'no-unused-keys': no_unused_keys_1.noUnusedKeys,
18
20
  'sort-properties': sort_properties_1.sortProperties,
19
21
  'format-properties': format_properties_1.formatProperties,
@@ -27,6 +29,7 @@ const configs = {
27
29
  '@plumeria/no-combinator': 'error',
28
30
  '@plumeria/no-destructure': 'error',
29
31
  '@plumeria/no-inner-call': 'error',
32
+ '@plumeria/no-unknown-css-properties': 'error',
30
33
  '@plumeria/no-unused-keys': 'warn',
31
34
  '@plumeria/sort-properties': 'warn',
32
35
  '@plumeria/format-properties': 'warn',
@@ -46,6 +49,7 @@ const flatConfigs = {
46
49
  '@plumeria/no-combinator': 'error',
47
50
  '@plumeria/no-destructure': 'error',
48
51
  '@plumeria/no-inner-call': 'error',
52
+ '@plumeria/no-unknown-css-properties': 'error',
49
53
  '@plumeria/no-unused-keys': 'warn',
50
54
  '@plumeria/sort-properties': 'warn',
51
55
  '@plumeria/format-properties': 'warn',
@@ -0,0 +1,2 @@
1
+ import type { Rule } from 'eslint';
2
+ export declare const noUnknownCssProperties: Rule.RuleModule;
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noUnknownCssProperties = void 0;
4
+ const known_css_properties_1 = require("known-css-properties");
5
+ const knownProperties = new Set(known_css_properties_1.all);
6
+ function toKebabCase(str) {
7
+ return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
8
+ }
9
+ exports.noUnknownCssProperties = {
10
+ meta: {
11
+ type: 'problem',
12
+ docs: {
13
+ description: 'Disallow unknown CSS properties in camelCase within css.create, css.keyframes, and css.viewTransition',
14
+ },
15
+ messages: {
16
+ unknownProperty: "Unknown CSS property '{{ name }}'.",
17
+ },
18
+ schema: [],
19
+ },
20
+ create(context) {
21
+ const plumeriaAliases = {};
22
+ return {
23
+ ImportDeclaration(node) {
24
+ if (node.source.value === '@plumeria/core') {
25
+ node.specifiers.forEach((specifier) => {
26
+ if (specifier.type === 'ImportNamespaceSpecifier' ||
27
+ specifier.type === 'ImportDefaultSpecifier') {
28
+ plumeriaAliases[specifier.local.name] = 'NAMESPACE';
29
+ }
30
+ else if (specifier.type === 'ImportSpecifier' &&
31
+ specifier.imported.type === 'Identifier') {
32
+ plumeriaAliases[specifier.local.name] = specifier.imported.name;
33
+ }
34
+ });
35
+ }
36
+ },
37
+ CallExpression(node) {
38
+ let isCssProperties = false;
39
+ if (node.callee.type === 'MemberExpression') {
40
+ if (node.callee.object.type === 'Identifier' &&
41
+ plumeriaAliases[node.callee.object.name] === 'NAMESPACE') {
42
+ const propertyName = node.callee.property.type === 'Identifier'
43
+ ? node.callee.property.name
44
+ : null;
45
+ if (propertyName === 'create' ||
46
+ propertyName === 'keyframes' ||
47
+ propertyName === 'viewTransition') {
48
+ isCssProperties = true;
49
+ }
50
+ }
51
+ }
52
+ else if (node.callee.type === 'Identifier') {
53
+ const alias = plumeriaAliases[node.callee.name];
54
+ if (alias === 'create' ||
55
+ alias === 'keyframes' ||
56
+ alias === 'viewTransition') {
57
+ isCssProperties = true;
58
+ }
59
+ }
60
+ if (isCssProperties) {
61
+ node.arguments.forEach((arg) => {
62
+ if (arg.type === 'ObjectExpression') {
63
+ arg.properties.forEach((prop) => {
64
+ if (prop.type === 'Property' &&
65
+ prop.value.type === 'ObjectExpression') {
66
+ checkStyleObject(prop.value);
67
+ }
68
+ });
69
+ }
70
+ });
71
+ }
72
+ },
73
+ };
74
+ function checkStyleObject(node) {
75
+ node.properties.forEach((prop) => {
76
+ if (prop.type === 'Property') {
77
+ let keyName = '';
78
+ if (prop.key.type === 'Identifier') {
79
+ keyName = prop.key.name;
80
+ }
81
+ else if (prop.key.type === 'Literal') {
82
+ keyName = String(prop.key.value);
83
+ }
84
+ if (keyName) {
85
+ if (!keyName.startsWith(':') &&
86
+ !keyName.startsWith('[') &&
87
+ !keyName.startsWith('@')) {
88
+ if (!keyName.startsWith('--')) {
89
+ const kebabName = toKebabCase(keyName);
90
+ if (!knownProperties.has(kebabName)) {
91
+ context.report({
92
+ node: prop.key,
93
+ messageId: 'unknownProperty',
94
+ data: {
95
+ name: keyName,
96
+ },
97
+ });
98
+ }
99
+ }
100
+ }
101
+ }
102
+ if (prop.value.type === 'ObjectExpression') {
103
+ checkStyleObject(prop.value);
104
+ }
105
+ }
106
+ });
107
+ }
108
+ },
109
+ };
@@ -136,7 +136,7 @@ exports.sortProperties = {
136
136
  misorderedIndices.forEach((i) => {
137
137
  const prop = properties[i];
138
138
  context.report({
139
- node: prop,
139
+ node: 'key' in prop ? prop.key : prop,
140
140
  messageId: 'sortProperties',
141
141
  data: {
142
142
  position: String(sorted.indexOf(prop) + 1),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/eslint-plugin",
3
- "version": "10.1.3",
3
+ "version": "10.2.1",
4
4
  "description": "Plumeria ESLint plugin",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -35,13 +35,16 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/eslint": "^9.6.1",
38
- "eslint": "^9.39.0",
39
- "@types/estree": "^1.0.8"
38
+ "@types/estree": "^1.0.8",
39
+ "eslint": "^9.39.0"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public",
43
43
  "provenance": true
44
44
  },
45
+ "dependencies": {
46
+ "known-css-properties": "^0.37.0"
47
+ },
45
48
  "scripts": {
46
49
  "build": "rimraf dist && pnpm cjs",
47
50
  "cjs": "tsc --project tsconfig.cjs.json"