@plumeria/eslint-plugin 17.0.0 → 18.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.
package/README.md CHANGED
@@ -30,7 +30,7 @@ export default [plumeria.configs.recommended];
30
30
  ## Configuring the styling prop
31
31
 
32
32
  Both `props-require-import` and `no-mixed-styling-props` need to know which JSX
33
- prop carries styles. It is `styleName` unless you changed it, so most projects
33
+ prop carries styles. It is `classStyle` unless you changed it, so most projects
34
34
  configure nothing.
35
35
 
36
36
  If you did rename it — via `styleProp` on `withPlumeria` or on the unplugin
@@ -81,7 +81,7 @@ Disallow destructuring APIs.
81
81
 
82
82
  ### no-inline-object
83
83
 
84
- Disallow passing inline object to `styleName`, `css.use()` and `css.variants()`. Only compiled styles from `css.create()` are allowed.
84
+ Disallow passing inline object to `classStyle`, `css.use()` and `css.variants()`. Only compiled styles from `css.create()` are allowed.
85
85
 
86
86
  ### no-inner-call
87
87
 
@@ -94,7 +94,7 @@ Disallow invalid selector inside `css.create()` and `css.keyframes()` and `css.v
94
94
 
95
95
  ### no-mixed-styling-props
96
96
 
97
- Disallow mixing the styling prop with `className` or `style`. `styleName` can handle both `className` and `style`.
97
+ Disallow mixing the styling prop with `className` or `style`. `classStyle` can handle both `className` and `style`.
98
98
 
99
99
  Accepts `{ styleProp }`; see [Configuring the styling prop](#configuring-the-styling-prop).
100
100
 
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.noInlineObject = void 0;
4
+ const style_prop_1 = require("../util/style-prop");
4
5
  function isPlumeriaMemberCall(node, aliases, method) {
5
6
  const callee = node.callee;
6
7
  if (callee.type === 'MemberExpression') {
@@ -20,16 +21,17 @@ exports.noInlineObject = {
20
21
  meta: {
21
22
  type: 'problem',
22
23
  docs: {
23
- description: 'Disallow inline objects in styleName and css.use',
24
+ description: 'Disallow inline objects in the styling prop and css.use',
24
25
  },
25
26
  messages: {
26
- noInlineObjectInStyleName: 'Do not pass inline objects to styleName. It only accepts compiled styles from css.create().',
27
+ noInlineObjectInStyleProp: 'Do not pass inline objects to "{{prop}}". It only accepts compiled styles from css.create().',
27
28
  noInlineObjectInCssUse: 'Do not pass inline objects to css.use(). It only accepts compiled styles from css.create().',
28
29
  noInlineObjectInCssVariants: 'Do not pass inline objects to css.variants(). It only accepts compiled styles from css.create().',
29
30
  },
30
- schema: [],
31
+ schema: style_prop_1.stylePropSchema,
31
32
  },
32
33
  create(context) {
34
+ const styleProp = (0, style_prop_1.resolveStyleProp)(context);
33
35
  const plumeriaAliases = {};
34
36
  return {
35
37
  ImportDeclaration(node) {
@@ -53,14 +55,15 @@ exports.noInlineObject = {
53
55
  },
54
56
  JSXAttribute(node) {
55
57
  if (node.name.type === 'JSXIdentifier' &&
56
- node.name.name === 'styleName') {
58
+ node.name.name === styleProp) {
57
59
  const value = node.value;
58
60
  if (value?.type === 'JSXExpressionContainer') {
59
61
  const expr = value.expression;
60
62
  if (expr.type === 'ObjectExpression') {
61
63
  context.report({
62
64
  node: expr,
63
- messageId: 'noInlineObjectInStyleName',
65
+ messageId: 'noInlineObjectInStyleProp',
66
+ data: { prop: styleProp },
64
67
  });
65
68
  }
66
69
  else if (expr.type === 'ArrayExpression') {
@@ -68,7 +71,8 @@ exports.noInlineObject = {
68
71
  if (el?.type === 'ObjectExpression') {
69
72
  context.report({
70
73
  node: el,
71
- messageId: 'noInlineObjectInStyleName',
74
+ messageId: 'noInlineObjectInStyleProp',
75
+ data: { prop: styleProp },
72
76
  });
73
77
  }
74
78
  });
@@ -520,6 +520,27 @@ function isValidTextDecorationLine(value) {
520
520
  return false;
521
521
  });
522
522
  }
523
+ function isValidContain(value) {
524
+ const singleValues = ['none', 'strict', 'content'];
525
+ const sizeValues = ['size', 'inline-size'];
526
+ const featureValues = ['layout', 'style', 'paint'];
527
+ const usedValues = new Set();
528
+ const trimmedValue = value.trim();
529
+ if (value !== trimmedValue)
530
+ return false;
531
+ const tokens = trimmedValue.split(/\s+/);
532
+ return tokens.every((token) => {
533
+ if (token.startsWith('var(') && varRegex.test(token))
534
+ return true;
535
+ if (singleValues.includes(token))
536
+ return tokens.length === 1;
537
+ if (sizeValues.includes(token))
538
+ return !usedValues.has('size') && usedValues.add('size');
539
+ if (featureValues.includes(token))
540
+ return !usedValues.has(token) && usedValues.add(token);
541
+ return false;
542
+ });
543
+ }
523
544
  function isValidFontVariantEastAsian(value) {
524
545
  const fontVariantEastAsianRegex = new RegExp('^' +
525
546
  `(?:jis78|jis83|jis90|jis04|simplified|traditional|full-width|proportional-width|ruby|${varString})` +
@@ -1297,6 +1318,9 @@ function getValidator(key) {
1297
1318
  const r = new RegExp(`^(${urlString}|${gradientString}|${imageSetString}|${attrString}|${counterString}|${countersString}|${stringString})$`);
1298
1319
  validator = (v) => r.test(v);
1299
1320
  }
1321
+ else if (['contain'].includes(key)) {
1322
+ validator = isValidContain;
1323
+ }
1300
1324
  else if (['columns'].includes(key)) {
1301
1325
  const r = new RegExp(`^(?:auto\\s*(?:auto|${lvp}|${numberPattern})?|${numberPattern}\\s*(?:auto|${lvp}|${numberPattern})?|${lvp}\\s*(?:auto|${lvp}|${numberPattern})?)$`);
1302
1326
  validator = (v) => r.test(v);
@@ -1,5 +1,5 @@
1
1
  import type { Rule } from 'eslint';
2
- export declare const DEFAULT_STYLE_PROP = "styleName";
2
+ export declare const DEFAULT_STYLE_PROP = "classStyle";
3
3
  export declare const stylePropSchema: {
4
4
  type: string;
5
5
  properties: {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stylePropSchema = exports.DEFAULT_STYLE_PROP = void 0;
4
4
  exports.resolveStyleProp = resolveStyleProp;
5
- exports.DEFAULT_STYLE_PROP = 'styleName';
5
+ exports.DEFAULT_STYLE_PROP = 'classStyle';
6
6
  exports.stylePropSchema = [
7
7
  {
8
8
  type: 'object',
@@ -316,7 +316,16 @@ const validData = {
316
316
  columnSpan: ['none', 'all'],
317
317
  columnWidth: ['auto', 'max-content', 'min-content'],
318
318
  columns: [],
319
- contain: ['none', 'strict', 'content'],
319
+ contain: [
320
+ 'none',
321
+ 'strict',
322
+ 'content',
323
+ 'size',
324
+ 'inline-size',
325
+ 'layout',
326
+ 'style',
327
+ 'paint',
328
+ ],
320
329
  containerType: ['size', 'inline-size', 'normal'],
321
330
  content: [
322
331
  'open-quote',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/eslint-plugin",
3
- "version": "17.0.0",
3
+ "version": "18.0.0",
4
4
  "description": "Plumeria ESLint plugin",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",