@plumeria/eslint-plugin 10.1.3 → 10.2.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.
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,105 @@
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',
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 isCssCreate = 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
+ isCssCreate = true;
47
+ }
48
+ }
49
+ }
50
+ else if (node.callee.type === 'Identifier') {
51
+ const alias = plumeriaAliases[node.callee.name];
52
+ if (alias === 'create') {
53
+ isCssCreate = true;
54
+ }
55
+ }
56
+ if (isCssCreate) {
57
+ node.arguments.forEach((arg) => {
58
+ if (arg.type === 'ObjectExpression') {
59
+ arg.properties.forEach((prop) => {
60
+ if (prop.type === 'Property' &&
61
+ prop.value.type === 'ObjectExpression') {
62
+ checkStyleObject(prop.value);
63
+ }
64
+ });
65
+ }
66
+ });
67
+ }
68
+ },
69
+ };
70
+ function checkStyleObject(node) {
71
+ node.properties.forEach((prop) => {
72
+ if (prop.type === 'Property') {
73
+ let keyName = '';
74
+ if (prop.key.type === 'Identifier') {
75
+ keyName = prop.key.name;
76
+ }
77
+ else if (prop.key.type === 'Literal') {
78
+ keyName = String(prop.key.value);
79
+ }
80
+ if (keyName) {
81
+ if (!keyName.startsWith(':') &&
82
+ !keyName.startsWith('[') &&
83
+ !keyName.startsWith('@')) {
84
+ if (!keyName.startsWith('--')) {
85
+ const kebabName = toKebabCase(keyName);
86
+ if (!knownProperties.has(kebabName)) {
87
+ context.report({
88
+ node: prop.key,
89
+ messageId: 'unknownProperty',
90
+ data: {
91
+ name: keyName,
92
+ },
93
+ });
94
+ }
95
+ }
96
+ }
97
+ }
98
+ if (prop.value.type === 'ObjectExpression') {
99
+ checkStyleObject(prop.value);
100
+ }
101
+ }
102
+ });
103
+ }
104
+ },
105
+ };
@@ -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.0",
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"