@xiaohe01/stylelint-config 1.0.1 β†’ 2.1.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
@@ -8,35 +8,30 @@
8
8
  [![github stars][github-stars-src]][github-stars-href]
9
9
  [![npm version][npm-version-src]][npm-version-href]
10
10
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
11
- [![bundle][bundle-src]][bundle-href]
12
11
  [![JSDocs][jsdocs-src]][jsdocs-href]
13
12
  [![License][license-src]][license-href]
14
13
 
15
- Xiaohe / [github@xiaohe0601](https://github.com/xiaohe0601) / [gitee@xiaohe0601](https://gitee.com/xiaohe0601)
14
+ xiaohe0601 / [github@xiaohe0601](https://github.com/xiaohe0601) / [gitee@xiaohe0601](https://gitee.com/xiaohe0601)
16
15
 
17
16
  ### 🚁 Installation
18
17
 
19
- #### PNPM
20
-
21
- ``` shell
18
+ ```shell
19
+ # pnpm
22
20
  pnpm add -D stylelint @xiaohe01/stylelint-config
23
- ```
24
21
 
25
- #### YARN
26
-
27
- ``` shell
22
+ # yarn
28
23
  yarn add --dev stylelint @xiaohe01/stylelint-config
29
- ```
30
24
 
31
- #### NPM
32
-
33
- ``` shell
25
+ # npm
34
26
  npm install -D stylelint @xiaohe01/stylelint-config
35
27
  ```
36
28
 
29
+ > [!WARNING]
30
+ > Stylelint `16.0.0+` is now required
31
+
37
32
  ### πŸ›Ή Usage
38
33
 
39
- Create `stylelint.config.js` in your project root
34
+ Create `stylelint.config.mjs` in your project root
40
35
 
41
36
  ```js
42
37
  import { defineConfig } from "@xiaohe01/stylelint-config";
@@ -57,13 +52,6 @@ Add script for `package.json`, for example
57
52
 
58
53
  For more information, please refer to [stylelint](https://stylelint.io).
59
54
 
60
- ### 🐢 Discussion & Communication
61
-
62
- - β“οΌšFor questions or bug feedback, you can submit an [issues](https://github.com/xiaohe0601/xiaohe-stylelint-config/issues)
63
- and PR are welcome
64
- - πŸ“«οΌš[xiaohe0601@outlook.com](mailto:xiaohe0601@outlook.com)
65
- - 🐧:Not yet available
66
-
67
55
  ### πŸ† License
68
56
 
69
57
  - MIT [LICENSE](./LICENSE)
@@ -74,8 +62,6 @@ For more information, please refer to [stylelint](https://stylelint.io).
74
62
  [npm-version-href]: https://npmjs.com/package/@xiaohe01/stylelint-config
75
63
  [npm-downloads-src]: https://img.shields.io/npm/dm/@xiaohe01/stylelint-config?style=flat&colorA=080f12&colorB=1fa669
76
64
  [npm-downloads-href]: https://npmjs.com/package/@xiaohe01/stylelint-config
77
- [bundle-src]: https://img.shields.io/bundlephobia/minzip/@xiaohe01/stylelint-config?style=flat&colorA=080f12&colorB=1fa669&label=minzip
78
- [bundle-href]: https://bundlephobia.com/result?p=@xiaohe01/stylelint-config
79
65
  [jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
80
66
  [jsdocs-href]: https://www.jsdocs.io/package/@xiaohe01/stylelint-config
81
67
  [license-src]: https://img.shields.io/github/license/xiaohe0601/xiaohe-stylelint-config.svg?style=flat&colorA=080f12&colorB=1fa669
package/dist/index.cjs CHANGED
@@ -1,8 +1,117 @@
1
1
  'use strict';
2
2
 
3
- const lodashEs = require('lodash-es');
4
3
  const localPkg = require('local-pkg');
5
4
 
5
+ const GLOB_CSS = ["*.css", "**/*.css"];
6
+ const GLOB_SCSS = ["*.scss", "**/*.scss"];
7
+ const GLOB_HTML = ["*.html", "**/*.html"];
8
+ const GLOB_VUE = ["*.vue", "**/*.vue"];
9
+ const GLOB_ALL = [
10
+ ...GLOB_CSS,
11
+ ...GLOB_SCSS,
12
+ ...GLOB_HTML,
13
+ ...GLOB_VUE
14
+ ];
15
+
16
+ function core(options = {}) {
17
+ return [
18
+ {
19
+ files: GLOB_ALL,
20
+ extends: [
21
+ "stylelint-config-recommended",
22
+ "stylelint-config-recess-order"
23
+ ],
24
+ rules: {
25
+ "alpha-value-notation": "number",
26
+ "color-function-notation": "legacy",
27
+ "color-hex-length": "long",
28
+ "declaration-block-no-redundant-longhand-properties": [
29
+ true,
30
+ {
31
+ ignoreShorthands: [
32
+ "inset"
33
+ ]
34
+ }
35
+ ],
36
+ "declaration-property-value-no-unknown": null,
37
+ "font-family-no-missing-generic-family-keyword": null,
38
+ "length-zero-no-unit": [
39
+ true,
40
+ {
41
+ ignore: ["custom-properties"],
42
+ ignoreFunctions: ["/^--/", "var"]
43
+ }
44
+ ],
45
+ "no-empty-source": null,
46
+ "selector-class-pattern": [
47
+ "^([#a-z][$#{}a-z0-9]*)((-{1,2}|_{2})[$#{}a-z0-9]+)*$",
48
+ {
49
+ message(selector) {
50
+ return `Expected class selector "${selector}" to be the BEM style (block-element[__element][--modifier]).`;
51
+ }
52
+ }
53
+ ],
54
+ "selector-not-notation": "simple",
55
+ "selector-type-no-unknown": null,
56
+ ...options.overrides
57
+ }
58
+ }
59
+ ];
60
+ }
61
+
62
+ function css(options = {}) {
63
+ return [
64
+ {
65
+ files: GLOB_CSS,
66
+ rules: {
67
+ ...options.overrides
68
+ }
69
+ }
70
+ ];
71
+ }
72
+
73
+ function html(options = {}) {
74
+ return [
75
+ {
76
+ files: GLOB_HTML,
77
+ extends: [
78
+ "stylelint-config-html/html"
79
+ ],
80
+ rules: {
81
+ ...options.overrides
82
+ }
83
+ }
84
+ ];
85
+ }
86
+
87
+ function scss(options = {}) {
88
+ return [
89
+ {
90
+ files: GLOB_SCSS,
91
+ extends: [
92
+ "stylelint-config-recommended-scss"
93
+ ],
94
+ rules: {
95
+ ...options.overrides
96
+ }
97
+ }
98
+ ];
99
+ }
100
+
101
+ function vue(options = {}) {
102
+ return [
103
+ {
104
+ files: GLOB_VUE,
105
+ extends: [
106
+ "stylelint-config-recommended-vue"
107
+ ],
108
+ rules: {
109
+ ...options.overrides
110
+ }
111
+ }
112
+ ];
113
+ }
114
+
6
115
  const SCSS_PACKAGES = [
7
116
  "sass",
8
117
  "sass-embedded",
@@ -14,158 +123,60 @@ const VUE_PACKAGES = [
14
123
  "vitepress",
15
124
  "@slidev/cli"
16
125
  ];
17
- const UNIAPP_PACKAGE = "@dcloudio/uni-app";
18
126
 
127
+ function castArray(value) {
128
+ return Array.isArray(value) ? value : [value];
129
+ }
19
130
  function isPkgExists(pkg) {
20
- return lodashEs.castArray(pkg).some((it) => localPkg.isPackageExists(it));
131
+ return castArray(pkg).some((it) => localPkg.isPackageExists(it));
21
132
  }
22
133
 
23
- function buildExtends(options) {
24
- if (!lodashEs.isEmpty(options.overrideExtends)) {
25
- return lodashEs.castArray(options.overrideExtends);
26
- }
134
+ function defineConfig(options = {}, ...userOverrides) {
27
135
  const {
28
- scss: enableScss,
29
- vue: enableVue
30
- } = options.presets;
31
- const extendz = [
32
- "stylelint-config-standard",
33
- "stylelint-config-recommended",
34
- "stylelint-config-html",
35
- "stylelint-config-recess-order"
36
- ];
37
- if (enableScss) {
38
- extendz.push("stylelint-config-standard-scss");
39
- }
40
- if (enableVue) {
41
- extendz.push("stylelint-config-recommended-vue");
42
- }
43
- if (!lodashEs.isEmpty(options.extends)) {
44
- extendz.push(...lodashEs.castArray(options.extends));
45
- }
46
- return extendz;
47
- }
48
- function buildPlugins(options) {
49
- if (!lodashEs.isEmpty(options.overridePlugins)) {
50
- return lodashEs.castArray(options.overridePlugins);
51
- }
52
- const plugins = [
53
- "stylelint-order"
136
+ css: enableCss = true,
137
+ html: enableHtml = true,
138
+ scss: enableScss = isPkgExists(SCSS_PACKAGES),
139
+ vue: enableVue = isPkgExists(VUE_PACKAGES)
140
+ } = options;
141
+ const overrides = [
142
+ ...core(normalizeOptions(options.core))
54
143
  ];
55
- if (!lodashEs.isEmpty(options.plugins)) {
56
- plugins.push(...lodashEs.castArray(options.plugins));
144
+ if (enableCss) {
145
+ overrides.push(
146
+ ...css(normalizeOptions(options.css))
147
+ );
57
148
  }
58
- return plugins;
59
- }
60
- function buildRules(options) {
61
- const {
62
- scss: enableScss,
63
- vue: enableVue,
64
- uniapp: enableUniApp
65
- } = options.presets;
66
- const disables = {
67
- "unit-no-unknown": null,
68
- "no-empty-source": null,
69
- "at-rule-no-unknown": null,
70
- "value-keyword-case": null,
71
- "selector-not-notation": null,
72
- "no-duplicate-selectors": null,
73
- "font-family-name-quotes": null,
74
- "no-descending-specificity": null,
75
- "custom-property-empty-line-before": null,
76
- "declaration-property-value-no-unknown": null,
77
- "font-family-no-missing-generic-family-keyword": null
78
- };
79
- if (enableScss) {
80
- lodashEs.merge(disables, {
81
- "scss/at-extend-no-missing-placeholder": null
82
- });
149
+ if (enableHtml) {
150
+ overrides.push(
151
+ ...html(normalizeOptions(options.html))
152
+ );
83
153
  }
84
- const rules = {
85
- ...disables,
86
- "color-hex-length": ["long", {
87
- message: "Hex color value should be used the long format style (#ffffff). (color-hex-length)"
88
- }],
89
- "length-zero-no-unit": [true, {
90
- ignoreFunctions: ["/^--/", "var", "calc"]
91
- }],
92
- "alpha-value-notation": "number",
93
- "selector-class-pattern": ["^([#a-z][$#{}a-z0-9]*)((-{1,2}|_{2})[$#{}a-z0-9]+)*$", {
94
- message: "Class naming should follow the BEM style (block-element[__element][--modifier]). (selector-class-pattern)"
95
- }],
96
- "color-function-notation": "legacy",
97
- "declaration-block-no-redundant-longhand-properties": [true, {
98
- ignoreShorthands: ["inset"]
99
- }]
100
- };
101
154
  if (enableScss) {
102
- lodashEs.merge(rules, {
103
- "scss/load-partial-extension": "always"
104
- });
155
+ overrides.push(
156
+ ...scss(normalizeOptions(options.scss))
157
+ );
105
158
  }
106
159
  if (enableVue) {
107
- lodashEs.merge(rules, {
108
- "selector-pseudo-class-no-unknown": [true, {
109
- ignorePseudoClasses: ["deep"]
110
- }]
111
- });
160
+ overrides.push(
161
+ ...vue(normalizeOptions(options.vue))
162
+ );
112
163
  }
113
- if (enableUniApp) {
114
- lodashEs.merge(rules, {
115
- "selector-type-no-unknown": null
116
- });
117
- }
118
- if (!lodashEs.isEmpty(options.rules)) {
119
- lodashEs.merge(rules, options.rules);
120
- }
121
- return rules;
122
- }
123
- function buildOverrides(options) {
124
- if (!lodashEs.isEmpty(options.overrideOverrides)) {
125
- return options.overrideOverrides;
126
- }
127
- const overrides = [{
128
- files: ["*.html", "*.vue"],
129
- customSyntax: "postcss-html"
130
- }, {
131
- files: ["*.scss"],
132
- customSyntax: "postcss-scss"
133
- }];
134
- if (!lodashEs.isEmpty(options.overrides)) {
135
- overrides.push(...lodashEs.castArray(options.overrides));
136
- }
137
- return overrides;
138
- }
139
- function defineConfig(options = {}) {
140
- const presets = lodashEs.merge({
141
- scss: isPkgExists(SCSS_PACKAGES),
142
- vue: isPkgExists(VUE_PACKAGES),
143
- uniapp: isPkgExists(UNIAPP_PACKAGE)
144
- }, options.presets);
145
- const finalOptions = {
146
- ...options,
147
- presets
148
- };
164
+ overrides.push(...userOverrides);
149
165
  return {
150
- allowEmptyInput: true,
151
- cache: true,
152
166
  defaultSeverity: "error",
153
- extends: buildExtends(finalOptions),
154
- plugins: buildPlugins(finalOptions),
155
- rules: buildRules(finalOptions),
156
- overrides: buildOverrides(finalOptions),
157
- ...lodashEs.omit(options, [
158
- "extends",
159
- "plugins",
160
- "rules",
161
- "overrides"
162
- ])
167
+ allowEmptyInput: true,
168
+ overrides,
169
+ rules: {},
170
+ ...options
163
171
  };
164
172
  }
173
+ function normalizeOptions(options) {
174
+ return typeof options === "boolean" ? {} : options || {};
175
+ }
165
176
 
166
- exports.SCSS_PACKAGES = SCSS_PACKAGES;
167
- exports.UNIAPP_PACKAGE = UNIAPP_PACKAGE;
168
- exports.VUE_PACKAGES = VUE_PACKAGES;
169
- exports.buildOverrides = buildOverrides;
177
+ exports.GLOB_ALL = GLOB_ALL;
178
+ exports.GLOB_CSS = GLOB_CSS;
179
+ exports.GLOB_HTML = GLOB_HTML;
180
+ exports.GLOB_SCSS = GLOB_SCSS;
181
+ exports.GLOB_VUE = GLOB_VUE;
170
182
  exports.defineConfig = defineConfig;
171
- exports.isPkgExists = isPkgExists;
package/dist/index.d.cts CHANGED
@@ -1,34 +1,55 @@
1
- import { Config, Plugin, ConfigRuleSettings } from 'stylelint';
2
-
3
- declare const SCSS_PACKAGES: string[];
4
- declare const VUE_PACKAGES: string[];
5
- declare const UNIAPP_PACKAGE = "@dcloudio/uni-app";
6
-
7
- type Arrayable<T> = T | T[];
8
- type ConfigExtend = string;
9
- type ConfigExtends = ConfigExtend[];
10
- type ConfigPlugin = string | Plugin;
11
- type ConfigPlugins = ConfigPlugin[];
12
- type ConfigRule = ConfigRuleSettings<any, object>;
13
- interface ConfigRules {
14
- [key: string]: ConfigRule;
15
- }
16
- type ConfigOverrides = Config["overrides"];
17
- interface ConfigPresets {
18
- scss?: boolean;
19
- vue?: boolean;
20
- uniapp?: boolean;
1
+ import type { Config } from 'stylelint';
2
+
3
+
4
+ type ConfigOverride = Omit<Config, "overrides"> & {
5
+ files: string | string[];
6
+ name?: string;
7
+ };
8
+ interface OptionsOverrides {
9
+ overrides?: Config["rules"];
21
10
  }
22
- interface ConfigOptions extends Config {
23
- presets?: ConfigPresets;
24
- overrideExtends?: Config["extends"];
25
- overridePlugins?: Config["plugins"];
26
- overrideOverrides?: Config["overrides"];
11
+ interface OptionsConfig {
12
+ /**
13
+ * Core rules. Can't be disabled.
14
+ */
15
+ core?: OptionsOverrides;
16
+ /**
17
+ * Enable CSS support.
18
+ *
19
+ * @default true
20
+ */
21
+ css?: boolean | OptionsOverrides;
22
+ /**
23
+ * Enable HTML support.
24
+ *
25
+ * @default true
26
+ */
27
+ html?: boolean | OptionsOverrides;
28
+ /**
29
+ * Enable Scss support.
30
+ *
31
+ * @default auto-detect based on the dependencies
32
+ */
33
+ scss?: boolean | OptionsOverrides;
34
+ /**
35
+ * Enable Vue support.
36
+ *
37
+ * @default auto-detect based on the dependencies
38
+ */
39
+ vue?: boolean | OptionsOverrides;
27
40
  }
28
41
 
29
- declare function buildOverrides(options: ConfigOptions): ConfigOverrides;
30
- declare function defineConfig(options?: ConfigOptions): Config;
31
42
 
32
- declare function isPkgExists(pkg: Arrayable<string>): boolean;
33
43
 
34
- export { type Arrayable, type ConfigExtend, type ConfigExtends, type ConfigOptions, type ConfigOverrides, type ConfigPlugin, type ConfigPlugins, type ConfigPresets, type ConfigRule, type ConfigRules, SCSS_PACKAGES, UNIAPP_PACKAGE, VUE_PACKAGES, buildOverrides, defineConfig, isPkgExists };
44
+
45
+
46
+
47
+ declare function defineConfig(options?: OptionsConfig & Omit<Config, "overrides">, ...userOverrides: ConfigOverride[]): Config;
48
+
49
+ declare const GLOB_CSS: string[];
50
+ declare const GLOB_SCSS: string[];
51
+ declare const GLOB_HTML: string[];
52
+ declare const GLOB_VUE: string[];
53
+ declare const GLOB_ALL: string[];
54
+
55
+ export { GLOB_ALL, GLOB_CSS, GLOB_HTML, GLOB_SCSS, GLOB_VUE, defineConfig };
package/dist/index.d.mts CHANGED
@@ -1,34 +1,55 @@
1
- import { Config, Plugin, ConfigRuleSettings } from 'stylelint';
2
-
3
- declare const SCSS_PACKAGES: string[];
4
- declare const VUE_PACKAGES: string[];
5
- declare const UNIAPP_PACKAGE = "@dcloudio/uni-app";
6
-
7
- type Arrayable<T> = T | T[];
8
- type ConfigExtend = string;
9
- type ConfigExtends = ConfigExtend[];
10
- type ConfigPlugin = string | Plugin;
11
- type ConfigPlugins = ConfigPlugin[];
12
- type ConfigRule = ConfigRuleSettings<any, object>;
13
- interface ConfigRules {
14
- [key: string]: ConfigRule;
15
- }
16
- type ConfigOverrides = Config["overrides"];
17
- interface ConfigPresets {
18
- scss?: boolean;
19
- vue?: boolean;
20
- uniapp?: boolean;
1
+ import type { Config } from 'stylelint';
2
+
3
+
4
+ type ConfigOverride = Omit<Config, "overrides"> & {
5
+ files: string | string[];
6
+ name?: string;
7
+ };
8
+ interface OptionsOverrides {
9
+ overrides?: Config["rules"];
21
10
  }
22
- interface ConfigOptions extends Config {
23
- presets?: ConfigPresets;
24
- overrideExtends?: Config["extends"];
25
- overridePlugins?: Config["plugins"];
26
- overrideOverrides?: Config["overrides"];
11
+ interface OptionsConfig {
12
+ /**
13
+ * Core rules. Can't be disabled.
14
+ */
15
+ core?: OptionsOverrides;
16
+ /**
17
+ * Enable CSS support.
18
+ *
19
+ * @default true
20
+ */
21
+ css?: boolean | OptionsOverrides;
22
+ /**
23
+ * Enable HTML support.
24
+ *
25
+ * @default true
26
+ */
27
+ html?: boolean | OptionsOverrides;
28
+ /**
29
+ * Enable Scss support.
30
+ *
31
+ * @default auto-detect based on the dependencies
32
+ */
33
+ scss?: boolean | OptionsOverrides;
34
+ /**
35
+ * Enable Vue support.
36
+ *
37
+ * @default auto-detect based on the dependencies
38
+ */
39
+ vue?: boolean | OptionsOverrides;
27
40
  }
28
41
 
29
- declare function buildOverrides(options: ConfigOptions): ConfigOverrides;
30
- declare function defineConfig(options?: ConfigOptions): Config;
31
42
 
32
- declare function isPkgExists(pkg: Arrayable<string>): boolean;
33
43
 
34
- export { type Arrayable, type ConfigExtend, type ConfigExtends, type ConfigOptions, type ConfigOverrides, type ConfigPlugin, type ConfigPlugins, type ConfigPresets, type ConfigRule, type ConfigRules, SCSS_PACKAGES, UNIAPP_PACKAGE, VUE_PACKAGES, buildOverrides, defineConfig, isPkgExists };
44
+
45
+
46
+
47
+ declare function defineConfig(options?: OptionsConfig & Omit<Config, "overrides">, ...userOverrides: ConfigOverride[]): Config;
48
+
49
+ declare const GLOB_CSS: string[];
50
+ declare const GLOB_SCSS: string[];
51
+ declare const GLOB_HTML: string[];
52
+ declare const GLOB_VUE: string[];
53
+ declare const GLOB_ALL: string[];
54
+
55
+ export { GLOB_ALL, GLOB_CSS, GLOB_HTML, GLOB_SCSS, GLOB_VUE, defineConfig };
package/dist/index.d.ts CHANGED
@@ -1,34 +1,55 @@
1
- import { Config, Plugin, ConfigRuleSettings } from 'stylelint';
2
-
3
- declare const SCSS_PACKAGES: string[];
4
- declare const VUE_PACKAGES: string[];
5
- declare const UNIAPP_PACKAGE = "@dcloudio/uni-app";
6
-
7
- type Arrayable<T> = T | T[];
8
- type ConfigExtend = string;
9
- type ConfigExtends = ConfigExtend[];
10
- type ConfigPlugin = string | Plugin;
11
- type ConfigPlugins = ConfigPlugin[];
12
- type ConfigRule = ConfigRuleSettings<any, object>;
13
- interface ConfigRules {
14
- [key: string]: ConfigRule;
15
- }
16
- type ConfigOverrides = Config["overrides"];
17
- interface ConfigPresets {
18
- scss?: boolean;
19
- vue?: boolean;
20
- uniapp?: boolean;
1
+ import type { Config } from 'stylelint';
2
+
3
+
4
+ type ConfigOverride = Omit<Config, "overrides"> & {
5
+ files: string | string[];
6
+ name?: string;
7
+ };
8
+ interface OptionsOverrides {
9
+ overrides?: Config["rules"];
21
10
  }
22
- interface ConfigOptions extends Config {
23
- presets?: ConfigPresets;
24
- overrideExtends?: Config["extends"];
25
- overridePlugins?: Config["plugins"];
26
- overrideOverrides?: Config["overrides"];
11
+ interface OptionsConfig {
12
+ /**
13
+ * Core rules. Can't be disabled.
14
+ */
15
+ core?: OptionsOverrides;
16
+ /**
17
+ * Enable CSS support.
18
+ *
19
+ * @default true
20
+ */
21
+ css?: boolean | OptionsOverrides;
22
+ /**
23
+ * Enable HTML support.
24
+ *
25
+ * @default true
26
+ */
27
+ html?: boolean | OptionsOverrides;
28
+ /**
29
+ * Enable Scss support.
30
+ *
31
+ * @default auto-detect based on the dependencies
32
+ */
33
+ scss?: boolean | OptionsOverrides;
34
+ /**
35
+ * Enable Vue support.
36
+ *
37
+ * @default auto-detect based on the dependencies
38
+ */
39
+ vue?: boolean | OptionsOverrides;
27
40
  }
28
41
 
29
- declare function buildOverrides(options: ConfigOptions): ConfigOverrides;
30
- declare function defineConfig(options?: ConfigOptions): Config;
31
42
 
32
- declare function isPkgExists(pkg: Arrayable<string>): boolean;
33
43
 
34
- export { type Arrayable, type ConfigExtend, type ConfigExtends, type ConfigOptions, type ConfigOverrides, type ConfigPlugin, type ConfigPlugins, type ConfigPresets, type ConfigRule, type ConfigRules, SCSS_PACKAGES, UNIAPP_PACKAGE, VUE_PACKAGES, buildOverrides, defineConfig, isPkgExists };
44
+
45
+
46
+
47
+ declare function defineConfig(options?: OptionsConfig & Omit<Config, "overrides">, ...userOverrides: ConfigOverride[]): Config;
48
+
49
+ declare const GLOB_CSS: string[];
50
+ declare const GLOB_SCSS: string[];
51
+ declare const GLOB_HTML: string[];
52
+ declare const GLOB_VUE: string[];
53
+ declare const GLOB_ALL: string[];
54
+
55
+ export { GLOB_ALL, GLOB_CSS, GLOB_HTML, GLOB_SCSS, GLOB_VUE, defineConfig };
package/dist/index.mjs CHANGED
@@ -1,6 +1,115 @@
1
- import { castArray, isEmpty, merge, omit } from 'lodash-es';
2
1
  import { isPackageExists } from 'local-pkg';
3
2
 
3
+ const GLOB_CSS = ["*.css", "**/*.css"];
4
+ const GLOB_SCSS = ["*.scss", "**/*.scss"];
5
+ const GLOB_HTML = ["*.html", "**/*.html"];
6
+ const GLOB_VUE = ["*.vue", "**/*.vue"];
7
+ const GLOB_ALL = [
8
+ ...GLOB_CSS,
9
+ ...GLOB_SCSS,
10
+ ...GLOB_HTML,
11
+ ...GLOB_VUE
12
+ ];
13
+
14
+ function core(options = {}) {
15
+ return [
16
+ {
17
+ files: GLOB_ALL,
18
+ extends: [
19
+ "stylelint-config-recommended",
20
+ "stylelint-config-recess-order"
21
+ ],
22
+ rules: {
23
+ "alpha-value-notation": "number",
24
+ "color-function-notation": "legacy",
25
+ "color-hex-length": "long",
26
+ "declaration-block-no-redundant-longhand-properties": [
27
+ true,
28
+ {
29
+ ignoreShorthands: [
30
+ "inset"
31
+ ]
32
+ }
33
+ ],
34
+ "declaration-property-value-no-unknown": null,
35
+ "font-family-no-missing-generic-family-keyword": null,
36
+ "length-zero-no-unit": [
37
+ true,
38
+ {
39
+ ignore: ["custom-properties"],
40
+ ignoreFunctions: ["/^--/", "var"]
41
+ }
42
+ ],
43
+ "no-empty-source": null,
44
+ "selector-class-pattern": [
45
+ "^([#a-z][$#{}a-z0-9]*)((-{1,2}|_{2})[$#{}a-z0-9]+)*$",
46
+ {
47
+ message(selector) {
48
+ return `Expected class selector "${selector}" to be the BEM style (block-element[__element][--modifier]).`;
49
+ }
50
+ }
51
+ ],
52
+ "selector-not-notation": "simple",
53
+ "selector-type-no-unknown": null,
54
+ ...options.overrides
55
+ }
56
+ }
57
+ ];
58
+ }
59
+
60
+ function css(options = {}) {
61
+ return [
62
+ {
63
+ files: GLOB_CSS,
64
+ rules: {
65
+ ...options.overrides
66
+ }
67
+ }
68
+ ];
69
+ }
70
+
71
+ function html(options = {}) {
72
+ return [
73
+ {
74
+ files: GLOB_HTML,
75
+ extends: [
76
+ "stylelint-config-html/html"
77
+ ],
78
+ rules: {
79
+ ...options.overrides
80
+ }
81
+ }
82
+ ];
83
+ }
84
+
85
+ function scss(options = {}) {
86
+ return [
87
+ {
88
+ files: GLOB_SCSS,
89
+ extends: [
90
+ "stylelint-config-recommended-scss"
91
+ ],
92
+ rules: {
93
+ ...options.overrides
94
+ }
95
+ }
96
+ ];
97
+ }
98
+
99
+ function vue(options = {}) {
100
+ return [
101
+ {
102
+ files: GLOB_VUE,
103
+ extends: [
104
+ "stylelint-config-recommended-vue"
105
+ ],
106
+ rules: {
107
+ ...options.overrides
108
+ }
109
+ }
110
+ ];
111
+ }
112
+
4
113
  const SCSS_PACKAGES = [
5
114
  "sass",
6
115
  "sass-embedded",
@@ -12,153 +121,55 @@ const VUE_PACKAGES = [
12
121
  "vitepress",
13
122
  "@slidev/cli"
14
123
  ];
15
- const UNIAPP_PACKAGE = "@dcloudio/uni-app";
16
124
 
125
+ function castArray(value) {
126
+ return Array.isArray(value) ? value : [value];
127
+ }
17
128
  function isPkgExists(pkg) {
18
129
  return castArray(pkg).some((it) => isPackageExists(it));
19
130
  }
20
131
 
21
- function buildExtends(options) {
22
- if (!isEmpty(options.overrideExtends)) {
23
- return castArray(options.overrideExtends);
24
- }
132
+ function defineConfig(options = {}, ...userOverrides) {
25
133
  const {
26
- scss: enableScss,
27
- vue: enableVue
28
- } = options.presets;
29
- const extendz = [
30
- "stylelint-config-standard",
31
- "stylelint-config-recommended",
32
- "stylelint-config-html",
33
- "stylelint-config-recess-order"
34
- ];
35
- if (enableScss) {
36
- extendz.push("stylelint-config-standard-scss");
37
- }
38
- if (enableVue) {
39
- extendz.push("stylelint-config-recommended-vue");
40
- }
41
- if (!isEmpty(options.extends)) {
42
- extendz.push(...castArray(options.extends));
43
- }
44
- return extendz;
45
- }
46
- function buildPlugins(options) {
47
- if (!isEmpty(options.overridePlugins)) {
48
- return castArray(options.overridePlugins);
49
- }
50
- const plugins = [
51
- "stylelint-order"
134
+ css: enableCss = true,
135
+ html: enableHtml = true,
136
+ scss: enableScss = isPkgExists(SCSS_PACKAGES),
137
+ vue: enableVue = isPkgExists(VUE_PACKAGES)
138
+ } = options;
139
+ const overrides = [
140
+ ...core(normalizeOptions(options.core))
52
141
  ];
53
- if (!isEmpty(options.plugins)) {
54
- plugins.push(...castArray(options.plugins));
142
+ if (enableCss) {
143
+ overrides.push(
144
+ ...css(normalizeOptions(options.css))
145
+ );
55
146
  }
56
- return plugins;
57
- }
58
- function buildRules(options) {
59
- const {
60
- scss: enableScss,
61
- vue: enableVue,
62
- uniapp: enableUniApp
63
- } = options.presets;
64
- const disables = {
65
- "unit-no-unknown": null,
66
- "no-empty-source": null,
67
- "at-rule-no-unknown": null,
68
- "value-keyword-case": null,
69
- "selector-not-notation": null,
70
- "no-duplicate-selectors": null,
71
- "font-family-name-quotes": null,
72
- "no-descending-specificity": null,
73
- "custom-property-empty-line-before": null,
74
- "declaration-property-value-no-unknown": null,
75
- "font-family-no-missing-generic-family-keyword": null
76
- };
77
- if (enableScss) {
78
- merge(disables, {
79
- "scss/at-extend-no-missing-placeholder": null
80
- });
147
+ if (enableHtml) {
148
+ overrides.push(
149
+ ...html(normalizeOptions(options.html))
150
+ );
81
151
  }
82
- const rules = {
83
- ...disables,
84
- "color-hex-length": ["long", {
85
- message: "Hex color value should be used the long format style (#ffffff). (color-hex-length)"
86
- }],
87
- "length-zero-no-unit": [true, {
88
- ignoreFunctions: ["/^--/", "var", "calc"]
89
- }],
90
- "alpha-value-notation": "number",
91
- "selector-class-pattern": ["^([#a-z][$#{}a-z0-9]*)((-{1,2}|_{2})[$#{}a-z0-9]+)*$", {
92
- message: "Class naming should follow the BEM style (block-element[__element][--modifier]). (selector-class-pattern)"
93
- }],
94
- "color-function-notation": "legacy",
95
- "declaration-block-no-redundant-longhand-properties": [true, {
96
- ignoreShorthands: ["inset"]
97
- }]
98
- };
99
152
  if (enableScss) {
100
- merge(rules, {
101
- "scss/load-partial-extension": "always"
102
- });
153
+ overrides.push(
154
+ ...scss(normalizeOptions(options.scss))
155
+ );
103
156
  }
104
157
  if (enableVue) {
105
- merge(rules, {
106
- "selector-pseudo-class-no-unknown": [true, {
107
- ignorePseudoClasses: ["deep"]
108
- }]
109
- });
158
+ overrides.push(
159
+ ...vue(normalizeOptions(options.vue))
160
+ );
110
161
  }
111
- if (enableUniApp) {
112
- merge(rules, {
113
- "selector-type-no-unknown": null
114
- });
115
- }
116
- if (!isEmpty(options.rules)) {
117
- merge(rules, options.rules);
118
- }
119
- return rules;
120
- }
121
- function buildOverrides(options) {
122
- if (!isEmpty(options.overrideOverrides)) {
123
- return options.overrideOverrides;
124
- }
125
- const overrides = [{
126
- files: ["*.html", "*.vue"],
127
- customSyntax: "postcss-html"
128
- }, {
129
- files: ["*.scss"],
130
- customSyntax: "postcss-scss"
131
- }];
132
- if (!isEmpty(options.overrides)) {
133
- overrides.push(...castArray(options.overrides));
134
- }
135
- return overrides;
136
- }
137
- function defineConfig(options = {}) {
138
- const presets = merge({
139
- scss: isPkgExists(SCSS_PACKAGES),
140
- vue: isPkgExists(VUE_PACKAGES),
141
- uniapp: isPkgExists(UNIAPP_PACKAGE)
142
- }, options.presets);
143
- const finalOptions = {
144
- ...options,
145
- presets
146
- };
162
+ overrides.push(...userOverrides);
147
163
  return {
148
- allowEmptyInput: true,
149
- cache: true,
150
164
  defaultSeverity: "error",
151
- extends: buildExtends(finalOptions),
152
- plugins: buildPlugins(finalOptions),
153
- rules: buildRules(finalOptions),
154
- overrides: buildOverrides(finalOptions),
155
- ...omit(options, [
156
- "extends",
157
- "plugins",
158
- "rules",
159
- "overrides"
160
- ])
165
+ allowEmptyInput: true,
166
+ overrides,
167
+ rules: {},
168
+ ...options
161
169
  };
162
170
  }
171
+ function normalizeOptions(options) {
172
+ return typeof options === "boolean" ? {} : options || {};
173
+ }
163
174
 
164
- export { SCSS_PACKAGES, UNIAPP_PACKAGE, VUE_PACKAGES, buildOverrides, defineConfig, isPkgExists };
175
+ export { GLOB_ALL, GLOB_CSS, GLOB_HTML, GLOB_SCSS, GLOB_VUE, defineConfig };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xiaohe01/stylelint-config",
3
3
  "type": "module",
4
- "version": "1.0.1",
4
+ "version": "2.1.0",
5
5
  "description": "🀚 Stylelint config preset for xiaohe",
6
6
  "author": "xiaohe0601 <xiaohe0601@outlook.com>",
7
7
  "license": "MIT",
@@ -38,21 +38,19 @@
38
38
  "dist"
39
39
  ],
40
40
  "dependencies": {
41
- "local-pkg": "^1.1.0",
42
- "lodash-es": "^4.17.21",
41
+ "local-pkg": "^1.1.1",
43
42
  "postcss-html": "^1.8.0",
44
43
  "postcss-scss": "^4.0.9",
45
44
  "stylelint-config-html": "^1.1.0",
46
45
  "stylelint-config-recess-order": "^6.0.0",
47
46
  "stylelint-config-recommended": "^15.0.0",
47
+ "stylelint-config-recommended-scss": "^14.1.0",
48
48
  "stylelint-config-recommended-vue": "^1.6.0",
49
- "stylelint-config-standard": "^37.0.0",
50
- "stylelint-config-standard-scss": "^14.0.0",
51
- "stylelint-order": "^6.0.4"
49
+ "stylelint-order": "^6.0.4",
50
+ "stylelint-scss": "^6.11.1"
52
51
  },
53
52
  "devDependencies": {
54
- "@types/lodash-es": "^4.17.12",
55
- "stylelint": "^16.14.1"
53
+ "stylelint": "^16.16.0"
56
54
  },
57
55
  "scripts": {
58
56
  "build": "unbuild"