@d-zero/stylelint-config 5.0.0-alpha.4 → 5.0.0-alpha.41

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 D-ZERO Co., Ltd.
3
+ Copyright (c) 2024 D-ZERO Co., Ltd.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,4 +1,54 @@
1
1
  # `@d-zero/stylelint-config`
2
2
 
3
- - 使用: 🆗 使用可
4
- - 解説: 🚧 準備中
3
+ ## 個別インストール
4
+
5
+ ```sh
6
+ yarn add -D @d-zero/stylelint-config
7
+ ```
8
+
9
+ ## 使い方
10
+
11
+ `.stylelintrc`を作成し、[`extends`](https://stylelint.io/user-guide/configure#extends)機能を使って読み込みます。
12
+
13
+ ```json
14
+ {
15
+ "extends": ["@d-zero/stylelint-config"]
16
+ }
17
+ ```
18
+
19
+ ### 拡張
20
+
21
+ プロジェクトに合わせて設定を追加します。
22
+
23
+ ```json
24
+ {
25
+ "extends": "@d-zero/stylelint-config",
26
+ "rules": {
27
+ // 例: @ルールで未知のルールを許可する
28
+ "at-rule-no-unknown": null
29
+ }
30
+ }
31
+ ```
32
+
33
+ ## 種類別プリセット
34
+
35
+ | パッケージパス | 用途 |
36
+ | --------------------------------- | ---------------- |
37
+ | `@d-zero/stylelint-config` | フルセット |
38
+ | `@d-zero/stylelint-config/base` | 基本セット |
39
+ | `@d-zero/stylelint-config/name` | 命名規則 |
40
+ | `@d-zero/stylelint-config/order` | プロパティの順番 |
41
+ | `@d-zero/stylelint-config/values` | プロパティ値 |
42
+ | `@d-zero/stylelint-config/scss` | SCSS関連 |
43
+
44
+ `@d-zero/stylelint-config`はすべてのルールを含んでいるので、一部のルールのみを利用する場合は、それぞれ種類別のものを利用します。
45
+
46
+ ```json
47
+ {
48
+ "extends": [
49
+ "@d-zero/stylelint-config/scss",
50
+ "@d-zero/stylelint-config/base",
51
+ "@d-zero/stylelint-config/values"
52
+ ]
53
+ }
54
+ ```
package/base.js CHANGED
@@ -1,34 +1,7 @@
1
1
  module.exports = {
2
- extends: ['stylelint-config-standard', 'stylelint-config-recess-order'],
3
- plugins: ['stylelint-scss', 'stylelint-order'],
2
+ plugins: ['stylelint-use-logical'],
3
+ extends: ['stylelint-config-standard'],
4
4
  rules: {
5
- 'order/order': [
6
- 'dollar-variables',
7
- 'custom-properties',
8
- {
9
- type: 'at-rule',
10
- name: 'custom-media',
11
- },
12
- {
13
- type: 'at-rule',
14
- name: 'extend',
15
- },
16
- {
17
- type: 'at-rule',
18
- name: 'mixin',
19
- },
20
- 'declarations',
21
- {
22
- type: 'at-rule',
23
- name: 'supports',
24
- },
25
- {
26
- type: 'at-rule',
27
- name: 'media',
28
- hasBlock: true,
29
- },
30
- 'rules',
31
- ],
32
5
  'at-rule-disallowed-list': null,
33
6
  'at-rule-empty-line-before': [
34
7
  'always',
@@ -38,12 +11,7 @@ module.exports = {
38
11
  },
39
12
  ],
40
13
  'at-rule-no-vendor-prefix': true,
41
- 'at-rule-no-unknown': [
42
- true,
43
- {
44
- ignoreAtRules: ['mixin', 'extend', 'for', 'if', 'include', 'use', 'forward'],
45
- },
46
- ],
14
+ 'at-rule-no-unknown': true,
47
15
  'color-hex-length': 'short',
48
16
  'color-named': 'never',
49
17
  'color-no-invalid-hex': true,
@@ -72,15 +40,11 @@ module.exports = {
72
40
  'function-calc-no-unspaced-operator': true,
73
41
  'function-linear-gradient-no-nonstandard-direction': true,
74
42
  'function-name-case': 'lower',
75
- 'function-no-unknown': [
76
- true,
77
- {
78
- ignoreFunctions: ['a', 'lighten', 'darken', 'resolve'],
79
- },
80
- ],
43
+ 'function-no-unknown': true,
81
44
  'function-url-scheme-allowed-list': null,
82
45
  'function-url-no-scheme-relative': true,
83
46
  'function-url-quotes': 'always',
47
+ 'import-notation': 'string',
84
48
  'keyframe-declaration-no-important': true,
85
49
  'length-zero-no-unit': true,
86
50
  'max-nesting-depth': 8,
@@ -111,8 +75,8 @@ module.exports = {
111
75
  'selector-attribute-operator-disallowed-list': null,
112
76
  'selector-attribute-quotes': 'always',
113
77
  'selector-max-compound-selectors': 8,
114
- 'selector-max-specificity': '0,10,10',
115
- 'selector-max-id': 0,
78
+ 'selector-max-specificity': null,
79
+ 'selector-max-id': [0, { message: 'スタイル定義でIDセレクタは使わないでください' }],
116
80
  'selector-max-universal': 1,
117
81
  'selector-no-vendor-prefix': true,
118
82
  'selector-pseudo-class-disallowed-list': ['link'],
@@ -127,15 +91,12 @@ module.exports = {
127
91
  'value-keyword-case': null,
128
92
  'value-no-vendor-prefix': true,
129
93
 
94
+ // Plugin stylelint-use-logical
95
+ 'csstools/use-logical': 'always',
96
+
130
97
  // Overwrite stylelint-config-standard
131
98
  'custom-media-pattern': null,
132
99
  'custom-property-pattern': null,
133
100
  'selector-class-pattern': null,
134
101
  },
135
- overrides: [
136
- {
137
- files: ['__assets/**/*.scss'],
138
- customSyntax: 'postcss-scss',
139
- },
140
- ],
141
102
  };
package/index.js CHANGED
@@ -1,18 +1,20 @@
1
1
  const base = require('./base');
2
2
  const name = require('./name');
3
+ const order = require('./order');
4
+ const scss = require('./scss');
3
5
  const values = require('./values');
4
6
 
5
7
  module.exports = {
8
+ ...scss,
6
9
  ...base,
7
- ignoreFiles: [
8
- '__assets/**/*.{js,jsx,ts,tsx,html,pug}',
9
- '__assets/css/_syntax-rules.scss',
10
- 'htdocs/**/*',
11
- 'docs/**/*.md',
12
- ],
10
+ extends: [...base.extends, ...order.extends],
11
+ plugins: [...scss.plugins, ...base.plugins, ...order.plugins, ...values.plugins],
12
+ ignoreFiles: ['**/*.{js,jsx,ts,tsx,html,pug}', 'htdocs/**/*', 'docs/**/*.md'],
13
13
  rules: {
14
14
  ...base.rules,
15
+ ...order.rules,
15
16
  ...name.rules,
16
17
  ...values.rules,
18
+ ...scss.rules,
17
19
  },
18
20
  };
package/name.js CHANGED
@@ -1,17 +1,41 @@
1
1
  module.exports = {
2
2
  rules: {
3
- 'scss/dollar-variable-pattern':
4
- '^(?:[a-z]{2,}-[a-z0-9-]+|_[a-z][a-z0-9]*(?:-[a-z0-9]+)*)$',
5
- 'scss/percent-placeholder-pattern': '^[a-z]{2,}(-[a-z0-9-]+)?$',
6
3
  'custom-media-pattern': '[a-z][a-z-]*',
7
4
  'custom-property-pattern': '[a-z][a-z-]*',
8
5
  'selector-class-pattern': [
9
6
  '^c-[a-z][a-z0-9]*(?:-[a-z0-9]+)*(?:__[a-z0-9]+(?:-[a-z0-9]+)*)?$',
10
7
  {
11
8
  resolveNestedSelectors: true,
9
+ /**
10
+ * @param {string} selector
11
+ * @returns {string}
12
+ */
13
+ message: (selector) => {
14
+ if (!selector.startsWith('.c-')) {
15
+ return `クラス名は「c-」から始めてください: ${selector}`;
16
+ }
17
+ if (selector.split('__').length > 2) {
18
+ return `「__」はコンポーネント名とエレメント名の区切りを表します。エレメント名の文字区切りは「-」を使います: ${selector}`;
19
+ }
20
+ return `クラス名に命名規則にない文字が含まれています: ${selector}`;
21
+ },
12
22
  },
13
23
  ],
14
- 'selector-id-pattern': '^$',
15
- 'selector-nested-pattern': '^[^.]+.*',
24
+ 'selector-nested-pattern': [
25
+ '^[^.]+.*',
26
+ {
27
+ /**
28
+ * @param {string} selector
29
+ * @returns {string}
30
+ */
31
+ message: (selector) => {
32
+ return `コンポーネントのスタイル定義の中で別のコンポーネントを定義してはいけません: ${selector}`;
33
+ },
34
+ },
35
+ ],
36
+
37
+ 'scss/dollar-variable-pattern':
38
+ '^(?:[a-z]{2,}-[a-z0-9-]+|_[a-z][a-z0-9]*(?:-[a-z0-9]+)*)$',
39
+ 'scss/percent-placeholder-pattern': '^[a-z]{2,}(-[a-z0-9-]+)?$',
16
40
  },
17
41
  };
package/order.js ADDED
@@ -0,0 +1,33 @@
1
+ module.exports = {
2
+ extends: ['stylelint-config-recess-order'],
3
+ plugins: ['stylelint-order'],
4
+ rules: {
5
+ 'order/order': [
6
+ 'dollar-variables',
7
+ 'custom-properties',
8
+ {
9
+ type: 'at-rule',
10
+ name: 'custom-media',
11
+ },
12
+ {
13
+ type: 'at-rule',
14
+ name: 'extend',
15
+ },
16
+ {
17
+ type: 'at-rule',
18
+ name: 'mixin',
19
+ },
20
+ 'declarations',
21
+ {
22
+ type: 'at-rule',
23
+ name: 'supports',
24
+ },
25
+ {
26
+ type: 'at-rule',
27
+ name: 'media',
28
+ hasBlock: true,
29
+ },
30
+ 'rules',
31
+ ],
32
+ },
33
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d-zero/stylelint-config",
3
- "version": "5.0.0-alpha.4",
3
+ "version": "5.0.0-alpha.41",
4
4
  "description": "Configurations of Stylelint",
5
5
  "repository": "https://github.com/d-zero-dev/linters.git",
6
6
  "author": "D-ZERO Co., Ltd.",
@@ -9,26 +9,31 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
+ "engines": {
13
+ "node": ">=22.0.0"
14
+ },
12
15
  "type": "commonjs",
13
16
  "exports": {
14
17
  ".": "./index.js",
15
18
  "./base": "./base.js",
16
19
  "./name": "./name.js",
20
+ "./order": "./order.js",
21
+ "./scss": "./scss.js",
17
22
  "./values": "./values.js"
18
23
  },
19
24
  "files": [
20
- "base.js",
21
- "index.js",
22
- "name.js",
23
- "values.js"
25
+ "*.js"
24
26
  ],
25
27
  "main": "index.js",
26
28
  "dependencies": {
27
- "stylelint": "16.2.0",
28
- "stylelint-config-recess-order": "4.4.0",
29
- "stylelint-config-standard": "36.0.0",
29
+ "@d-zero/stylelint-rules": "5.0.0-alpha.41",
30
+ "postcss-scss": "4.0.9",
31
+ "stylelint": "16.8.1",
32
+ "stylelint-config-recess-order": "5.0.1",
33
+ "stylelint-config-standard": "36.0.1",
30
34
  "stylelint-order": "6.0.4",
31
- "stylelint-scss": "6.1.0"
35
+ "stylelint-scss": "6.4.1",
36
+ "stylelint-use-logical": "2.1.2"
32
37
  },
33
- "gitHead": "de8f9c035cfb70bbf4cc5b203869dc39427c9d3a"
38
+ "gitHead": "25f71f1dfef6d627b908f832124d4e4a0b1572bb"
34
39
  }
package/scss.js ADDED
@@ -0,0 +1,18 @@
1
+ module.exports = {
2
+ customSyntax: 'postcss-scss',
3
+ plugins: ['stylelint-scss'],
4
+ rules: {
5
+ 'at-rule-no-unknown': [
6
+ true,
7
+ {
8
+ ignoreAtRules: ['mixin', 'extend', 'for', 'if', 'include', 'use', 'forward'],
9
+ },
10
+ ],
11
+ 'function-no-unknown': [
12
+ true,
13
+ {
14
+ ignoreFunctions: ['a', 'lighten', 'darken', 'resolve'],
15
+ },
16
+ ],
17
+ },
18
+ };
package/values.js CHANGED
@@ -1,19 +1,17 @@
1
+ /**
2
+ * @see https://drafts.csswg.org/css-values-4/#viewport-relative-lengths
3
+ */
4
+ const VIEWPORT_PERCENTAGE_LENGTHS = '[ls]?v(?:w|h|i|d|max|min)';
5
+
6
+ const PERCENTATE_UNITS = `(?:%|${VIEWPORT_PERCENTAGE_LENGTHS})`;
7
+
1
8
  module.exports = {
9
+ plugins: ['@d-zero/stylelint-rules'],
2
10
  rules: {
3
11
  'declaration-property-value-disallowed-list': {
4
12
  '/^(?:color|background|background-color|border|border-color|outline|outline-color)$/':
5
- ['/#[0-9a-f]{3}/', '/(?:rgb|hsl)a?\\(.+?\\)/'],
6
- content: ['/^\\"\\\\[0-9a-fA-F]{1,6}\\"$/'],
7
- flex: ['/calc/'],
8
- '/^(?:max-|min-)?(?:width|height)|^flex/': [
9
- '/[1-9]*\\.[0-9]+(?:%|vw|vh)/',
10
- '/(?:^|[^0-9])[0-9](?:%|vw|vh)/',
11
- '/(?:^|[^0-9])[0-9]{2}(?:%|vw|vh)/',
12
- '/1[0-9][1-9](?:%|vw|vh)/',
13
- '/1[1-9][0-9](?:%|vw|vh)/',
14
- '/[2-9][0-9][0-9](?:%|vw|vh)/',
15
- '/[0-9]{4,}(?:%|vw|vh)/',
16
- ],
13
+ ['/#[0-9a-f]{3}/', String.raw`/(?:rgb|hsl)a?\(.+?\)/`],
14
+ content: [String.raw`/^\"\\[0-9a-fA-F]{1,6}\"$/`],
17
15
  },
18
16
  'declaration-property-value-allowed-list': {
19
17
  'font-size': [
@@ -21,10 +19,19 @@ module.exports = {
21
19
  '$root-font-size',
22
20
  '$base-font-size',
23
21
  '1em',
24
- '/^calc\\((?:\\$[a-z_][a-z0-9_-]*|(?:[0-9]*\\.)?[0-9]+) \\/ (?:\\$[a-z_][a-z0-9_-]*|(?:[0-9]*\\.)?[0-9]+) \\* (?:1em|100vw)\\)$/',
25
- '/^(?:[0-9]*\\.)?[0-9]+rem/',
26
- '/^clamp\\(/',
22
+ String.raw`/^calc\(\s*(?:\$[a-z_][a-z0-9_-]*|(?:[0-9]*\.)?[0-9]+) \/ (?:\$[a-z_][a-z0-9_-]*|(?:[0-9]*\.)?[0-9]+) \* (?:1em|100vw)\s*\)$/`,
23
+ String.raw`/^(?:[0-9]*\.)?[0-9]+rem/`,
24
+ String.raw`/^clamp\(/`,
25
+ // Custom properties
26
+ String.raw`/^var\(/`,
27
+ ],
28
+ flex: [
29
+ String.raw`/^\s*[01]\s+[01]\s.+/`,
30
+ // Custom properties
31
+ String.raw`/^var\(/`,
27
32
  ],
33
+ 'flex-grow': ['0', '1'],
34
+ 'flex-shrink': ['0', '1'],
28
35
  },
29
36
  'unit-disallowed-list': [
30
37
  'ex',
@@ -44,8 +51,31 @@ module.exports = {
44
51
  'value-keyword-case': [
45
52
  'lower',
46
53
  {
47
- ignoreProperties: ['/^\\$font-family-/'],
54
+ ignoreProperties: [String.raw`/^\$font-family-/`],
48
55
  },
49
56
  ],
57
+
58
+ '@d-zero/declaration-value-type-disallowed-list': {
59
+ '/^length|percentage$/': {
60
+ ignoreProperties: ['font-size'],
61
+ patterns: [
62
+ // float
63
+ `/[1-9]*\\.[0-9]+${PERCENTATE_UNITS}/`,
64
+
65
+ // 1% - 99%
66
+ `/[1-9][0-9]?${PERCENTATE_UNITS}/`,
67
+
68
+ // 101% - 199%
69
+ `/1[0-9][1-9]${PERCENTATE_UNITS}/`,
70
+ `/1[1-9][0-9]${PERCENTATE_UNITS}/`,
71
+
72
+ // 200% - 999%
73
+ `/[2-9][0-9][0-9]${PERCENTATE_UNITS}/`,
74
+
75
+ // 1000% or larger
76
+ `/[1-9][0-9]{3,}${PERCENTATE_UNITS}/`,
77
+ ],
78
+ },
79
+ },
50
80
  },
51
81
  };