@xiaohe01/stylelint-config 1.0.0 β†’ 2.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
@@ -8,35 +8,27 @@
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
 
37
29
  ### πŸ›Ή Usage
38
30
 
39
- Create `stylelint.config.js` in your project root
31
+ Create `stylelint.config.mjs` in your project root
40
32
 
41
33
  ```js
42
34
  import { defineConfig } from "@xiaohe01/stylelint-config";
@@ -57,13 +49,6 @@ Add script for `package.json`, for example
57
49
 
58
50
  For more information, please refer to [stylelint](https://stylelint.io).
59
51
 
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
52
  ### πŸ† License
68
53
 
69
54
  - MIT [LICENSE](./LICENSE)
@@ -74,8 +59,6 @@ For more information, please refer to [stylelint](https://stylelint.io).
74
59
  [npm-version-href]: https://npmjs.com/package/@xiaohe01/stylelint-config
75
60
  [npm-downloads-src]: https://img.shields.io/npm/dm/@xiaohe01/stylelint-config?style=flat&colorA=080f12&colorB=1fa669
76
61
  [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
62
  [jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
80
63
  [jsdocs-href]: https://www.jsdocs.io/package/@xiaohe01/stylelint-config
81
64
  [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,7 +1,116 @@
1
1
  'use strict';
2
2
 
3
- const lodashEs = require('lodash-es');
4
3
  const localPkg = require('local-pkg');
4
+ const lodashEs = require('lodash-es');
5
+
6
+ const GLOB_CSS = ["*.css", "**/*.css"];
7
+ const GLOB_SCSS = ["*.scss", "**/*.scss"];
8
+ const GLOB_HTML = ["*.html", "**/*.html"];
9
+ const GLOB_VUE = ["*.vue", "**/*.vue"];
10
+
11
+ function common(config = {}) {
12
+ return {
13
+ defaultSeverity: "error",
14
+ allowEmptyInput: true,
15
+ files: [
16
+ ...GLOB_CSS,
17
+ ...GLOB_SCSS,
18
+ ...GLOB_HTML,
19
+ ...GLOB_VUE
20
+ ],
21
+ extends: [
22
+ "stylelint-config-standard",
23
+ "stylelint-config-recess-order"
24
+ ],
25
+ rules: {
26
+ "alpha-value-notation": "number",
27
+ "color-function-notation": "legacy",
28
+ "color-hex-length": "long",
29
+ "declaration-block-no-redundant-longhand-properties": [
30
+ true,
31
+ {
32
+ ignoreShorthands: [
33
+ "inset"
34
+ ]
35
+ }
36
+ ],
37
+ "declaration-property-value-no-unknown": null,
38
+ "font-family-no-missing-generic-family-keyword": null,
39
+ "length-zero-no-unit": [
40
+ true,
41
+ {
42
+ ignore: ["custom-properties"],
43
+ ignoreFunctions: ["/^--/", "var"]
44
+ }
45
+ ],
46
+ "no-empty-source": null,
47
+ "selector-class-pattern": [
48
+ "^([#a-z][$#{}a-z0-9]*)((-{1,2}|_{2})[$#{}a-z0-9]+)*$",
49
+ {
50
+ message(selector) {
51
+ return `Expected class selector "${selector}" to be the BEM style (block-element[__element][--modifier]).`;
52
+ }
53
+ }
54
+ ],
55
+ "selector-not-notation": "simple",
56
+ "selector-type-no-unknown": null,
57
+ ...config.rules
58
+ },
59
+ ...lodashEs.omit(config, ["rules"])
60
+ };
61
+ }
62
+
63
+ function css(config = {}) {
64
+ return {
65
+ files: GLOB_CSS,
66
+ rules: {
67
+ ...config.rules
68
+ },
69
+ ...lodashEs.omit(config, ["rules"])
70
+ };
71
+ }
72
+
73
+ function html(config = {}) {
74
+ return {
75
+ files: GLOB_HTML,
76
+ customSyntax: "postcss-html",
77
+ rules: {
78
+ ...config.rules
79
+ },
80
+ ...lodashEs.omit(config, ["rules"])
81
+ };
82
+ }
83
+
84
+ function scss(config = {}) {
85
+ return {
86
+ files: GLOB_SCSS,
87
+ customSyntax: "postcss-scss",
88
+ extends: [
89
+ "stylelint-config-standard-scss"
90
+ ],
91
+ plugins: [
92
+ "stylelint-scss"
93
+ ],
94
+ rules: {
95
+ ...config.rules
96
+ },
97
+ ...lodashEs.omit(config, ["rules"])
98
+ };
99
+ }
100
+
101
+ function vue(config = {}) {
102
+ return {
103
+ files: GLOB_VUE,
104
+ customSyntax: "postcss-html",
105
+ extends: [
106
+ "stylelint-config-recommended-vue"
107
+ ],
108
+ rules: {
109
+ ...config.rules
110
+ },
111
+ ...lodashEs.omit(config, ["rules"])
112
+ };
113
+ }
5
114
 
6
115
  const SCSS_PACKAGES = [
7
116
  "sass",
@@ -14,157 +123,41 @@ const VUE_PACKAGES = [
14
123
  "vitepress",
15
124
  "@slidev/cli"
16
125
  ];
17
- const UNIAPP_PACKAGE = "@dcloudio/uni-app";
18
126
 
19
127
  function isPkgExists(pkg) {
20
128
  return lodashEs.castArray(pkg).some((it) => localPkg.isPackageExists(it));
21
129
  }
22
130
 
23
- function buildExtends(options) {
24
- if (!lodashEs.isEmpty(options.overrideExtends)) {
25
- return lodashEs.castArray(options.overrideExtends);
26
- }
27
- 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"
54
- ];
55
- if (!lodashEs.isEmpty(options.plugins)) {
56
- plugins.push(...lodashEs.castArray(options.plugins));
57
- }
58
- return plugins;
131
+ function getUserOverride(config) {
132
+ return typeof config === "boolean" ? {} : config || {};
59
133
  }
60
- function buildRules(options) {
134
+ function defineConfig(config = {}) {
61
135
  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
- "font-family-no-missing-generic-family-keyword": null
77
- };
78
- if (enableScss) {
79
- lodashEs.merge(disables, {
80
- "scss/at-extend-no-missing-placeholder": null
81
- });
82
- }
83
- const rules = {
84
- ...disables,
85
- "color-hex-length": ["long", {
86
- message: "Hex color value should be used the long format style (#ffffff). (color-hex-length)"
87
- }],
88
- "length-zero-no-unit": [true, {
89
- ignoreFunctions: ["/^--/", "var", "calc"]
90
- }],
91
- "alpha-value-notation": "number",
92
- "selector-class-pattern": ["^([#a-z][$#{}a-z0-9]*)((-{1,2}|_{2})[$#{}a-z0-9]+)*$", {
93
- message: "Class naming should follow the BEM style (block-element[__element][--modifier]). (selector-class-pattern)"
94
- }],
95
- "color-function-notation": "legacy",
96
- "declaration-block-no-redundant-longhand-properties": [true, {
97
- ignoreShorthands: ["inset"]
98
- }]
99
- };
136
+ scss: enableScss = isPkgExists(SCSS_PACKAGES),
137
+ vue: enableVue = isPkgExists(VUE_PACKAGES)
138
+ } = config;
139
+ const overrides = [
140
+ common(config.common),
141
+ css(config.css),
142
+ html(config.html)
143
+ ];
100
144
  if (enableScss) {
101
- lodashEs.merge(rules, {
102
- "scss/load-partial-extension": "always"
103
- });
145
+ overrides.push(
146
+ scss(getUserOverride(config.scss))
147
+ );
104
148
  }
105
149
  if (enableVue) {
106
- lodashEs.merge(rules, {
107
- "selector-pseudo-class-no-unknown": [true, {
108
- ignorePseudoClasses: ["deep"]
109
- }]
110
- });
111
- }
112
- if (enableUniApp) {
113
- lodashEs.merge(rules, {
114
- "selector-type-no-unknown": null
115
- });
116
- }
117
- if (!lodashEs.isEmpty(options.rules)) {
118
- lodashEs.merge(rules, options.rules);
150
+ overrides.push(
151
+ vue(getUserOverride(config.vue))
152
+ );
119
153
  }
120
- return rules;
121
- }
122
- function buildOverrides(options) {
123
- if (!lodashEs.isEmpty(options.overrideOverrides)) {
124
- return options.overrideOverrides;
125
- }
126
- const overrides = [{
127
- files: ["*.html", "*.vue"],
128
- customSyntax: "postcss-html"
129
- }, {
130
- files: ["*.scss"],
131
- customSyntax: "postcss-scss"
132
- }];
133
- if (!lodashEs.isEmpty(options.overrides)) {
134
- overrides.push(...lodashEs.castArray(options.overrides));
154
+ if (config.overrides) {
155
+ overrides.push(...config.overrides);
135
156
  }
136
- return overrides;
137
- }
138
- function defineConfig(options = {}) {
139
- const presets = lodashEs.merge({
140
- scss: isPkgExists(SCSS_PACKAGES),
141
- vue: isPkgExists(VUE_PACKAGES),
142
- uniapp: isPkgExists(UNIAPP_PACKAGE)
143
- }, options.presets);
144
- const finalOptions = {
145
- ...options,
146
- presets
147
- };
148
157
  return {
149
- allowEmptyInput: true,
150
- cache: true,
151
- defaultSeverity: "error",
152
- extends: buildExtends(finalOptions),
153
- plugins: buildPlugins(finalOptions),
154
- rules: buildRules(finalOptions),
155
- overrides: buildOverrides(finalOptions),
156
- ...lodashEs.omit(options, [
157
- "extends",
158
- "plugins",
159
- "rules",
160
- "overrides"
161
- ])
158
+ overrides,
159
+ rules: {}
162
160
  };
163
161
  }
164
162
 
165
- exports.SCSS_PACKAGES = SCSS_PACKAGES;
166
- exports.UNIAPP_PACKAGE = UNIAPP_PACKAGE;
167
- exports.VUE_PACKAGES = VUE_PACKAGES;
168
- exports.buildOverrides = buildOverrides;
169
163
  exports.defineConfig = defineConfig;
170
- exports.isPkgExists = isPkgExists;
package/dist/index.d.cts CHANGED
@@ -1,34 +1,23 @@
1
- import { Config, Plugin, ConfigRuleSettings } from 'stylelint';
1
+ import type { Config } from 'stylelint';
2
2
 
3
- declare const SCSS_PACKAGES: string[];
4
- declare const VUE_PACKAGES: string[];
5
- declare const UNIAPP_PACKAGE = "@dcloudio/uni-app";
6
3
 
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;
21
- }
22
- interface ConfigOptions extends Config {
23
- presets?: ConfigPresets;
24
- overrideExtends?: Config["extends"];
25
- overridePlugins?: Config["plugins"];
26
- overrideOverrides?: Config["overrides"];
4
+ type ConfigOverride = Omit<Config, "overrides"> & {
5
+ files: string | string[];
6
+ name?: string;
7
+ };
8
+ type UserConfigOverride = Omit<ConfigOverride, "files">;
9
+ interface UserConfig {
10
+ common?: UserConfigOverride;
11
+ css?: UserConfigOverride;
12
+ html?: UserConfigOverride;
13
+ scss?: boolean | UserConfigOverride;
14
+ vue?: boolean | UserConfigOverride;
15
+ overrides?: ConfigOverride[];
27
16
  }
28
17
 
29
- declare function buildOverrides(options: ConfigOptions): ConfigOverrides;
30
- declare function defineConfig(options?: ConfigOptions): Config;
31
18
 
32
- declare function isPkgExists(pkg: Arrayable<string>): boolean;
33
19
 
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 };
20
+
21
+ declare function defineConfig(config?: UserConfig): Config;
22
+
23
+ export { defineConfig };
package/dist/index.d.mts CHANGED
@@ -1,34 +1,23 @@
1
- import { Config, Plugin, ConfigRuleSettings } from 'stylelint';
1
+ import type { Config } from 'stylelint';
2
2
 
3
- declare const SCSS_PACKAGES: string[];
4
- declare const VUE_PACKAGES: string[];
5
- declare const UNIAPP_PACKAGE = "@dcloudio/uni-app";
6
3
 
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;
21
- }
22
- interface ConfigOptions extends Config {
23
- presets?: ConfigPresets;
24
- overrideExtends?: Config["extends"];
25
- overridePlugins?: Config["plugins"];
26
- overrideOverrides?: Config["overrides"];
4
+ type ConfigOverride = Omit<Config, "overrides"> & {
5
+ files: string | string[];
6
+ name?: string;
7
+ };
8
+ type UserConfigOverride = Omit<ConfigOverride, "files">;
9
+ interface UserConfig {
10
+ common?: UserConfigOverride;
11
+ css?: UserConfigOverride;
12
+ html?: UserConfigOverride;
13
+ scss?: boolean | UserConfigOverride;
14
+ vue?: boolean | UserConfigOverride;
15
+ overrides?: ConfigOverride[];
27
16
  }
28
17
 
29
- declare function buildOverrides(options: ConfigOptions): ConfigOverrides;
30
- declare function defineConfig(options?: ConfigOptions): Config;
31
18
 
32
- declare function isPkgExists(pkg: Arrayable<string>): boolean;
33
19
 
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 };
20
+
21
+ declare function defineConfig(config?: UserConfig): Config;
22
+
23
+ export { defineConfig };
package/dist/index.d.ts CHANGED
@@ -1,34 +1,23 @@
1
- import { Config, Plugin, ConfigRuleSettings } from 'stylelint';
1
+ import type { Config } from 'stylelint';
2
2
 
3
- declare const SCSS_PACKAGES: string[];
4
- declare const VUE_PACKAGES: string[];
5
- declare const UNIAPP_PACKAGE = "@dcloudio/uni-app";
6
3
 
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;
21
- }
22
- interface ConfigOptions extends Config {
23
- presets?: ConfigPresets;
24
- overrideExtends?: Config["extends"];
25
- overridePlugins?: Config["plugins"];
26
- overrideOverrides?: Config["overrides"];
4
+ type ConfigOverride = Omit<Config, "overrides"> & {
5
+ files: string | string[];
6
+ name?: string;
7
+ };
8
+ type UserConfigOverride = Omit<ConfigOverride, "files">;
9
+ interface UserConfig {
10
+ common?: UserConfigOverride;
11
+ css?: UserConfigOverride;
12
+ html?: UserConfigOverride;
13
+ scss?: boolean | UserConfigOverride;
14
+ vue?: boolean | UserConfigOverride;
15
+ overrides?: ConfigOverride[];
27
16
  }
28
17
 
29
- declare function buildOverrides(options: ConfigOptions): ConfigOverrides;
30
- declare function defineConfig(options?: ConfigOptions): Config;
31
18
 
32
- declare function isPkgExists(pkg: Arrayable<string>): boolean;
33
19
 
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 };
20
+
21
+ declare function defineConfig(config?: UserConfig): Config;
22
+
23
+ export { defineConfig };
package/dist/index.mjs CHANGED
@@ -1,5 +1,114 @@
1
- import { castArray, isEmpty, merge, omit } from 'lodash-es';
2
1
  import { isPackageExists } from 'local-pkg';
2
+ import { omit, castArray } from 'lodash-es';
3
+
4
+ const GLOB_CSS = ["*.css", "**/*.css"];
5
+ const GLOB_SCSS = ["*.scss", "**/*.scss"];
6
+ const GLOB_HTML = ["*.html", "**/*.html"];
7
+ const GLOB_VUE = ["*.vue", "**/*.vue"];
8
+
9
+ function common(config = {}) {
10
+ return {
11
+ defaultSeverity: "error",
12
+ allowEmptyInput: true,
13
+ files: [
14
+ ...GLOB_CSS,
15
+ ...GLOB_SCSS,
16
+ ...GLOB_HTML,
17
+ ...GLOB_VUE
18
+ ],
19
+ extends: [
20
+ "stylelint-config-standard",
21
+ "stylelint-config-recess-order"
22
+ ],
23
+ rules: {
24
+ "alpha-value-notation": "number",
25
+ "color-function-notation": "legacy",
26
+ "color-hex-length": "long",
27
+ "declaration-block-no-redundant-longhand-properties": [
28
+ true,
29
+ {
30
+ ignoreShorthands: [
31
+ "inset"
32
+ ]
33
+ }
34
+ ],
35
+ "declaration-property-value-no-unknown": null,
36
+ "font-family-no-missing-generic-family-keyword": null,
37
+ "length-zero-no-unit": [
38
+ true,
39
+ {
40
+ ignore: ["custom-properties"],
41
+ ignoreFunctions: ["/^--/", "var"]
42
+ }
43
+ ],
44
+ "no-empty-source": null,
45
+ "selector-class-pattern": [
46
+ "^([#a-z][$#{}a-z0-9]*)((-{1,2}|_{2})[$#{}a-z0-9]+)*$",
47
+ {
48
+ message(selector) {
49
+ return `Expected class selector "${selector}" to be the BEM style (block-element[__element][--modifier]).`;
50
+ }
51
+ }
52
+ ],
53
+ "selector-not-notation": "simple",
54
+ "selector-type-no-unknown": null,
55
+ ...config.rules
56
+ },
57
+ ...omit(config, ["rules"])
58
+ };
59
+ }
60
+
61
+ function css(config = {}) {
62
+ return {
63
+ files: GLOB_CSS,
64
+ rules: {
65
+ ...config.rules
66
+ },
67
+ ...omit(config, ["rules"])
68
+ };
69
+ }
70
+
71
+ function html(config = {}) {
72
+ return {
73
+ files: GLOB_HTML,
74
+ customSyntax: "postcss-html",
75
+ rules: {
76
+ ...config.rules
77
+ },
78
+ ...omit(config, ["rules"])
79
+ };
80
+ }
81
+
82
+ function scss(config = {}) {
83
+ return {
84
+ files: GLOB_SCSS,
85
+ customSyntax: "postcss-scss",
86
+ extends: [
87
+ "stylelint-config-standard-scss"
88
+ ],
89
+ plugins: [
90
+ "stylelint-scss"
91
+ ],
92
+ rules: {
93
+ ...config.rules
94
+ },
95
+ ...omit(config, ["rules"])
96
+ };
97
+ }
98
+
99
+ function vue(config = {}) {
100
+ return {
101
+ files: GLOB_VUE,
102
+ customSyntax: "postcss-html",
103
+ extends: [
104
+ "stylelint-config-recommended-vue"
105
+ ],
106
+ rules: {
107
+ ...config.rules
108
+ },
109
+ ...omit(config, ["rules"])
110
+ };
111
+ }
3
112
 
4
113
  const SCSS_PACKAGES = [
5
114
  "sass",
@@ -12,152 +121,41 @@ const VUE_PACKAGES = [
12
121
  "vitepress",
13
122
  "@slidev/cli"
14
123
  ];
15
- const UNIAPP_PACKAGE = "@dcloudio/uni-app";
16
124
 
17
125
  function isPkgExists(pkg) {
18
126
  return castArray(pkg).some((it) => isPackageExists(it));
19
127
  }
20
128
 
21
- function buildExtends(options) {
22
- if (!isEmpty(options.overrideExtends)) {
23
- return castArray(options.overrideExtends);
24
- }
25
- 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"
52
- ];
53
- if (!isEmpty(options.plugins)) {
54
- plugins.push(...castArray(options.plugins));
55
- }
56
- return plugins;
129
+ function getUserOverride(config) {
130
+ return typeof config === "boolean" ? {} : config || {};
57
131
  }
58
- function buildRules(options) {
132
+ function defineConfig(config = {}) {
59
133
  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
- "font-family-no-missing-generic-family-keyword": null
75
- };
76
- if (enableScss) {
77
- merge(disables, {
78
- "scss/at-extend-no-missing-placeholder": null
79
- });
80
- }
81
- const rules = {
82
- ...disables,
83
- "color-hex-length": ["long", {
84
- message: "Hex color value should be used the long format style (#ffffff). (color-hex-length)"
85
- }],
86
- "length-zero-no-unit": [true, {
87
- ignoreFunctions: ["/^--/", "var", "calc"]
88
- }],
89
- "alpha-value-notation": "number",
90
- "selector-class-pattern": ["^([#a-z][$#{}a-z0-9]*)((-{1,2}|_{2})[$#{}a-z0-9]+)*$", {
91
- message: "Class naming should follow the BEM style (block-element[__element][--modifier]). (selector-class-pattern)"
92
- }],
93
- "color-function-notation": "legacy",
94
- "declaration-block-no-redundant-longhand-properties": [true, {
95
- ignoreShorthands: ["inset"]
96
- }]
97
- };
134
+ scss: enableScss = isPkgExists(SCSS_PACKAGES),
135
+ vue: enableVue = isPkgExists(VUE_PACKAGES)
136
+ } = config;
137
+ const overrides = [
138
+ common(config.common),
139
+ css(config.css),
140
+ html(config.html)
141
+ ];
98
142
  if (enableScss) {
99
- merge(rules, {
100
- "scss/load-partial-extension": "always"
101
- });
143
+ overrides.push(
144
+ scss(getUserOverride(config.scss))
145
+ );
102
146
  }
103
147
  if (enableVue) {
104
- merge(rules, {
105
- "selector-pseudo-class-no-unknown": [true, {
106
- ignorePseudoClasses: ["deep"]
107
- }]
108
- });
109
- }
110
- if (enableUniApp) {
111
- merge(rules, {
112
- "selector-type-no-unknown": null
113
- });
114
- }
115
- if (!isEmpty(options.rules)) {
116
- merge(rules, options.rules);
148
+ overrides.push(
149
+ vue(getUserOverride(config.vue))
150
+ );
117
151
  }
118
- return rules;
119
- }
120
- function buildOverrides(options) {
121
- if (!isEmpty(options.overrideOverrides)) {
122
- return options.overrideOverrides;
123
- }
124
- const overrides = [{
125
- files: ["*.html", "*.vue"],
126
- customSyntax: "postcss-html"
127
- }, {
128
- files: ["*.scss"],
129
- customSyntax: "postcss-scss"
130
- }];
131
- if (!isEmpty(options.overrides)) {
132
- overrides.push(...castArray(options.overrides));
152
+ if (config.overrides) {
153
+ overrides.push(...config.overrides);
133
154
  }
134
- return overrides;
135
- }
136
- function defineConfig(options = {}) {
137
- const presets = merge({
138
- scss: isPkgExists(SCSS_PACKAGES),
139
- vue: isPkgExists(VUE_PACKAGES),
140
- uniapp: isPkgExists(UNIAPP_PACKAGE)
141
- }, options.presets);
142
- const finalOptions = {
143
- ...options,
144
- presets
145
- };
146
155
  return {
147
- allowEmptyInput: true,
148
- cache: true,
149
- defaultSeverity: "error",
150
- extends: buildExtends(finalOptions),
151
- plugins: buildPlugins(finalOptions),
152
- rules: buildRules(finalOptions),
153
- overrides: buildOverrides(finalOptions),
154
- ...omit(options, [
155
- "extends",
156
- "plugins",
157
- "rules",
158
- "overrides"
159
- ])
156
+ overrides,
157
+ rules: {}
160
158
  };
161
159
  }
162
160
 
163
- export { SCSS_PACKAGES, UNIAPP_PACKAGE, VUE_PACKAGES, buildOverrides, defineConfig, isPkgExists };
161
+ export { 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.0",
4
+ "version": "2.0.0",
5
5
  "description": "🀚 Stylelint config preset for xiaohe",
6
6
  "author": "xiaohe0601 <xiaohe0601@outlook.com>",
7
7
  "license": "MIT",
@@ -38,21 +38,21 @@
38
38
  "dist"
39
39
  ],
40
40
  "dependencies": {
41
- "local-pkg": "^1.1.0",
41
+ "local-pkg": "^1.1.1",
42
42
  "lodash-es": "^4.17.21",
43
43
  "postcss-html": "^1.8.0",
44
44
  "postcss-scss": "^4.0.9",
45
- "stylelint-config-html": "^1.1.0",
46
45
  "stylelint-config-recess-order": "^6.0.0",
47
46
  "stylelint-config-recommended": "^15.0.0",
48
47
  "stylelint-config-recommended-vue": "^1.6.0",
49
48
  "stylelint-config-standard": "^37.0.0",
50
49
  "stylelint-config-standard-scss": "^14.0.0",
51
- "stylelint-order": "^6.0.4"
50
+ "stylelint-order": "^6.0.4",
51
+ "stylelint-scss": "^6.11.1"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/lodash-es": "^4.17.12",
55
- "stylelint": "^16.14.1"
55
+ "stylelint": "^16.16.0"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "unbuild"