@xiaohe01/stylelint-config 1.0.1 β†’ 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,158 +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
- "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
- });
83
- }
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
- };
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
+ ];
101
144
  if (enableScss) {
102
- lodashEs.merge(rules, {
103
- "scss/load-partial-extension": "always"
104
- });
145
+ overrides.push(
146
+ scss(getUserOverride(config.scss))
147
+ );
105
148
  }
106
149
  if (enableVue) {
107
- lodashEs.merge(rules, {
108
- "selector-pseudo-class-no-unknown": [true, {
109
- ignorePseudoClasses: ["deep"]
110
- }]
111
- });
112
- }
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);
150
+ overrides.push(
151
+ vue(getUserOverride(config.vue))
152
+ );
120
153
  }
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));
154
+ if (config.overrides) {
155
+ overrides.push(...config.overrides);
136
156
  }
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
- };
149
157
  return {
150
- allowEmptyInput: true,
151
- cache: true,
152
- 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
- ])
158
+ overrides,
159
+ rules: {}
163
160
  };
164
161
  }
165
162
 
166
- exports.SCSS_PACKAGES = SCSS_PACKAGES;
167
- exports.UNIAPP_PACKAGE = UNIAPP_PACKAGE;
168
- exports.VUE_PACKAGES = VUE_PACKAGES;
169
- exports.buildOverrides = buildOverrides;
170
163
  exports.defineConfig = defineConfig;
171
- 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,153 +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
- "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
- });
81
- }
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
- };
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
+ ];
99
142
  if (enableScss) {
100
- merge(rules, {
101
- "scss/load-partial-extension": "always"
102
- });
143
+ overrides.push(
144
+ scss(getUserOverride(config.scss))
145
+ );
103
146
  }
104
147
  if (enableVue) {
105
- merge(rules, {
106
- "selector-pseudo-class-no-unknown": [true, {
107
- ignorePseudoClasses: ["deep"]
108
- }]
109
- });
110
- }
111
- if (enableUniApp) {
112
- merge(rules, {
113
- "selector-type-no-unknown": null
114
- });
115
- }
116
- if (!isEmpty(options.rules)) {
117
- merge(rules, options.rules);
148
+ overrides.push(
149
+ vue(getUserOverride(config.vue))
150
+ );
118
151
  }
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));
152
+ if (config.overrides) {
153
+ overrides.push(...config.overrides);
134
154
  }
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
- };
147
155
  return {
148
- allowEmptyInput: true,
149
- cache: true,
150
- 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
- ])
156
+ overrides,
157
+ rules: {}
161
158
  };
162
159
  }
163
160
 
164
- 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.1",
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"