stylelint-taro 4.0.0-alpha.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/LICENSE ADDED
@@ -0,0 +1,160 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 O2Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ========================================================================
24
+
25
+ MIT (react-devtools):
26
+ The following files embed [react-devtools](https://github.com/facebook/react) MIT:
27
+ `/packages/taro-plugin-react-devtools/src/backend/index.js`
28
+ See `/LICENSE` for details of the license.
29
+
30
+ ==================
31
+
32
+ MIT (vue-devtools):
33
+ The following files embed [vue-devtools](https://github.com/vuejs/devtools) MIT:
34
+ `/packages/taro-plugin-vue-devtools/src/backend/*`
35
+ See `/LICENSE` for details of the license.
36
+
37
+ ==================
38
+
39
+ MIT (vite):
40
+ The following files embed [vite](https://github.com/vitejs/vite) MIT:
41
+ `/packages/taro-webpack5-prebundle/src/prebundle/scanImport.ts`,
42
+ `/packages/taro-webpack5-prebundle/src/prebundle/bundle.ts`,
43
+ `/packages/taro-webpack5-prebundle/src/h5.ts`,
44
+ `/packages/taro-webpack5-prebundle/src/min.ts`
45
+ See `/LICENSE` for details of the license.
46
+
47
+ ==================
48
+
49
+ MIT (webpack):
50
+ The following files embed [webpack](https://github.com/webpack/webpack) MIT:
51
+ `/packages/taro-webpack5-prebundle/src/webpack/TaroContainerEntryModule.ts`,
52
+ `/packages/taro-webpack5-prebundle/src/webpack/TaroContainerPlugin.ts`,
53
+ `/packages/taro-webpack5-prebundle/src/webpack/TaroContainerReferencePlugin.ts`,
54
+ `/packages/taro-webpack5-prebundle/src/webpack/TaroModuleFederationPlugin.ts`
55
+ See `/LICENSE` for details of the license.
56
+
57
+ ==================
58
+
59
+ MIT (sizzle):
60
+ The following files embed [sizzle](https://github.com/jquery/sizzle) MIT:
61
+ `/packages/taro-extends/src/jquery/sizzle.js`
62
+ See `/LICENSE.txt` for details of the license.
63
+
64
+ ==================
65
+
66
+ MIT (zepto):
67
+ The following files embed [zepto](https://github.com/madrobby/zepto) MIT:
68
+ `/packages/taro-extends/src/jquery/zepto.js`,
69
+ `/packages/taro-extends/src/jquery/event.js`
70
+ See `/MIT-LICENSE` for details of the license.
71
+
72
+ ==================
73
+
74
+ MIT (css-to-react-native):
75
+ The following files embed [css-to-react-native](https://github.com/styled-components/css-to-react-native) MIT:
76
+ `/packages/css-to-react-native/src/css-to-react-native/*`
77
+ See `/LICENSE.md` for details of the license.
78
+
79
+ ==================
80
+
81
+ MIT (reactify-wc):
82
+ The following files embed [reactify-wc](https://github.com/BBKolton/reactify-wc) MIT:
83
+ `/packages/taro-components-library-react/src/component-lib/reactify-wc.ts`
84
+ See `/LICENSE` for details of the license.
85
+
86
+ ==================
87
+
88
+ MIT (ant-design-mobile-rn):
89
+ The following files embed [ant-design-mobile-rn](https://github.com/ant-design/ant-design-mobile-rn) MIT:
90
+ `/packages/taro-components-rn/src/components/Swiper/carousel.tsx`
91
+ See `/LICENSE` for details of the license.
92
+
93
+ ==================
94
+
95
+ MIT (react-wx-images-viewer):
96
+ The following files embed [react-wx-images-viewer](https://github.com/react-ld/react-wx-images-viewer) MIT:
97
+ `/packages/taro-h5/src/api/media/image/previewImage.ts`
98
+ See `/LICENSE` for details of the license.
99
+
100
+ ==================
101
+
102
+ MIT (webpack-contrib/css-loader):
103
+ The following files embed [webpack-contrib/css-loader](https://github.com/webpack-contrib/css-loader) MIT:
104
+ `/packages/taro-rn-style-transformer/src/utils/index.ts`
105
+ See `/LICENSE` for details of the license.
106
+
107
+ ==================
108
+
109
+ MIT (react-native):
110
+ The following files embed [react-native](https://github.com/facebook/react-native) MIT:
111
+ `/packages/taro-rn-style-transformer/src/transforms/StyleSheet/*`
112
+ See `/LICENSE` for details of the license.
113
+
114
+ ==================
115
+
116
+ MIT (myrne/performance-now):
117
+ The following files embed [myrne/performance-now](https://github.com/myrne/performance-now) MIT:
118
+ `/packages/taro-runtime/src/bom/raf.ts`
119
+ See `/LICENSE` for details of the license.
120
+
121
+ ==================
122
+
123
+ Apache (chameleon-api):
124
+ The following files embed [chameleon-api](https://github.com/chameleon-team/chameleon-api) Apache:
125
+ `/packages/taro-h5/src/api/device/clipboard.ts`
126
+
127
+ ==================
128
+
129
+ MIT (uni-app):
130
+ The following files embed [uni-app](https://github.com/dcloudio/uni-app) MIT:
131
+ `/packages/taro-components-rn/src/components/Video/index.tsx`
132
+ See `/LICENSE` for details of the license.
133
+
134
+ ==================
135
+
136
+ MIT (miniprogram-render):
137
+ The following files embed [miniprogram-render](https://github.com/Tencent/kbone) MIT:
138
+ `/packages/taro-plugin-http/src/runtime/Cookie.ts`
139
+ See `/LICENSE` for details of the license.
140
+
141
+ ==================
142
+
143
+ MIT (stencil-ds-output-targets):
144
+ The following files embed [stencil-ds-output-targets](https://github.com/ionic-team/stencil-ds-output-targets/) MIT:
145
+ `/packages/taro-components-library-react/src/react-component-lib/utils/attachProps.ts`
146
+ `/packages/taro-components-library-react/src/react-component-lib/utils/case.ts`
147
+ `/packages/taro-components-library-react/src/react-component-lib/utils/dev.ts`
148
+ `/packages/taro-components-library-react/src/react-component-lib/utils/index.tsx`
149
+ `/packages/taro-components-library-react/src/react-component-lib/createComponent.tsx`
150
+ `/packages/taro-components-library-react/src/react-component-lib/createOverlayComponent.tsx`
151
+ `/packages/taro-components-library-react/src/react-component-lib/interfaces.ts`
152
+ `/packages/taro-components-library-vue3/src/vue-component-lib/utils.ts`
153
+ See `/LICENSE` for details of the license.
154
+
155
+ ==================
156
+
157
+ MIT (stencil-vue2-output-target):
158
+ The following files embed [stencil-vue2-output-target](https://github.com/diondree/stencil-vue2-output-target) MIT:
159
+ `/packages/taro-components-library-vue2/src/vue-component-lib/utils.ts`
160
+ See `/LICENSE` for details of the license.
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # stylelint-taro
2
+
3
+ **Taro 多端融合校验工具**
4
+
5
+ 我们可以根据我们需要适配多少个端,根据不同端所支持的最小样式子集进行样式校验:
6
+
7
+ ## 安装
8
+
9
+ ```
10
+ yarn add -D stylelint-taro
11
+ ```
12
+
13
+ ## 使用
14
+
15
+ ```js
16
+ // .stylelintrc.js
17
+ const mergeConfig = require('stylelint-taro/lib/config')
18
+
19
+ // 合并配置,填写需要适配的端:"h5", "miniprogram", "harmony", "rn"
20
+ module.exports = mergeConfig(['h5', 'miniprogram', 'harmony'], {
21
+ // 自定义样式规范: 支持sass的语言规范
22
+ // customSyntax: "postcss-scss"
23
+ // 自定义Stylelint配置
24
+ rules: {},
25
+ })
26
+ ```
27
+
28
+ ## 内置 rule
29
+
30
+ ### taro/no-nested-selectors
31
+
32
+ 仅能使用 class 选择器
33
+
34
+ ```js
35
+ // .stylelintrc.js
36
+ module.exports = mergeConfig(['harmony'], {})
37
+ ```
38
+
39
+ ```css
40
+ /* 通过检查 */
41
+ ✅ .hello {
42
+ /* ... */
43
+ }
44
+ /* 警告提示:harmony平台仅能使用单类选择器 */
45
+ ❌ #a {
46
+ }
47
+ ❌ .a .b {
48
+ }
49
+ ❌ #a .b {
50
+ }
51
+ ❌ .a > .b {
52
+ }
53
+ ❌ .a + .b {
54
+ }
55
+ ❌ .a ~ .b {
56
+ }
57
+ ```
58
+
59
+ ### taro/property-allowed-list
60
+
61
+ 允许的属性列表
62
+
63
+ ### taro/declaration-property-value-allowed-list
64
+
65
+ 允许的属性及其对应的值
66
+
67
+ ```js
68
+ {
69
+ plugins: ['stylelint-taro']
70
+ rules: {
71
+ 'taro/declaration-property-value-allowed-list': {
72
+ harmony: {
73
+ 'color': true, // 支持color属性及所有合法值
74
+ 'text-align': ['left', 'right'], // 仅支持left、right 2个值
75
+ 'height': [/^-?\d+(\.\d+)?(px|vw|vh|%)?$/i] // 支持匹配height为length
76
+ },
77
+ rn: {
78
+ 'text-align': ['left', 'center'], // 仅支持left、center 2个值
79
+ }
80
+ }
81
+ }
82
+ }
83
+ ```
84
+
85
+ 如果在支持`rn`和`harmony`的情况下:
86
+
87
+ ```js
88
+ // .stylelintrc.js
89
+ module.exports = mergeConfig(['harmony', 'rn'], {})
90
+ ```
91
+
92
+ ```css
93
+ /* 通过检查 */
94
+ ✅ .hello {
95
+ text-align: left;
96
+ }
97
+ /* 警告提示 */
98
+ ❌ .hello2 {
99
+ /* rn平台的text-align属性暂不支持right */
100
+ text-align: right;
101
+ }
102
+ ```
103
+
104
+ ## 开启 VSCODE 校验
105
+
106
+ 项目空间内,建议通过修改 settings.json 配置
107
+
108
+ ```json
109
+ // .vscode/settings.json
110
+ {
111
+ "stylelint.enable": true,
112
+ "stylelint.validate": ["css", "sass", "scss", "less", "postcss"]
113
+ }
114
+ ```
package/lib/config.js ADDED
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const lodash_1 = __importDefault(require("lodash"));
7
+ const h5_1 = __importDefault(require("./platform/h5"));
8
+ const harmony_1 = __importDefault(require("./platform/harmony"));
9
+ const miniprogram_1 = __importDefault(require("./platform/miniprogram"));
10
+ const rn_1 = __importDefault(require("./platform/rn"));
11
+ // 合并平台规则成并集
12
+ function mergeRule(platforms) {
13
+ const rules = {};
14
+ // 合并选择器
15
+ platforms.forEach(({ config: platform }) => {
16
+ if (platform.disAllowedSelectors) {
17
+ Object.keys(platform.disAllowedSelectors).forEach(ruleName => {
18
+ const rule = platform.disAllowedSelectors[ruleName];
19
+ if (rules[ruleName]) {
20
+ if (rule instanceof Array) {
21
+ rules[ruleName] = lodash_1.default.intersection(rules[ruleName], rule);
22
+ }
23
+ else {
24
+ rules[ruleName] = lodash_1.default.merge(rules[ruleName], rule);
25
+ }
26
+ }
27
+ else {
28
+ rules[ruleName] = rule;
29
+ }
30
+ });
31
+ }
32
+ });
33
+ // 支持的属性列表
34
+ let supportPropertiesCheck = false;
35
+ const properties = {};
36
+ platforms.forEach(({ name, config }) => {
37
+ if (config.supportedProperties) {
38
+ if (['harmony', 'rn'].includes(name)) {
39
+ supportPropertiesCheck = true;
40
+ }
41
+ properties[name] = Object.assign({}, config.supportedProperties);
42
+ }
43
+ });
44
+ // 只有harmony和rn支持
45
+ if (supportPropertiesCheck) {
46
+ // rules['taro/no-nested-selectors'] = true
47
+ rules['taro/property-allowed-list'] = properties;
48
+ rules['taro/declaration-property-value-allowed-list'] = properties;
49
+ }
50
+ // 合并规则
51
+ platforms.forEach(({ config }) => {
52
+ if (config.rules) {
53
+ Object.keys(config.rules).forEach(ruleName => {
54
+ const rule = config.rules[ruleName];
55
+ if (rules[ruleName]) {
56
+ if (rule instanceof Array) {
57
+ rules[ruleName] = lodash_1.default.intersection(rules[ruleName], rule);
58
+ }
59
+ else if (rule instanceof Boolean) {
60
+ rules[ruleName] = rules[ruleName] || rule;
61
+ }
62
+ else {
63
+ rules[ruleName] = rule;
64
+ }
65
+ }
66
+ else {
67
+ rules[ruleName] = rule;
68
+ }
69
+ });
70
+ }
71
+ });
72
+ Object.keys(rules).forEach(ruleName => {
73
+ rules[ruleName] = [
74
+ rules[ruleName],
75
+ {
76
+ severity: 'warning'
77
+ }
78
+ ];
79
+ });
80
+ return rules;
81
+ }
82
+ const ruleMap = { harmony: harmony_1.default, rn: rn_1.default, miniprogram: miniprogram_1.default, h5: h5_1.default };
83
+ // 根据平台生成规则
84
+ function taroRules(platforms = []) {
85
+ return mergeRule(platforms.map((platform) => ({
86
+ name: platform,
87
+ config: ruleMap[platform]
88
+ })));
89
+ }
90
+ function getPlatformConfigs(platforms) {
91
+ return platforms.map((platform) => ruleMap[platform]).filter(Boolean);
92
+ }
93
+ // 到处合并配置的方法
94
+ module.exports = function mergeConfig(platforms, stylelintConfig) {
95
+ // 注入环境变量
96
+ process.env.__PLATFORMS__ = platforms.join(',');
97
+ // 插件合并
98
+ let plugins = stylelintConfig.plugins || [];
99
+ const platformConfigs = getPlatformConfigs(platforms);
100
+ platformConfigs.forEach((platform) => {
101
+ if (platform.plugins) {
102
+ if (plugins instanceof Array) {
103
+ if (platform.plugins instanceof Array) {
104
+ plugins.push(...platform.plugins);
105
+ }
106
+ else {
107
+ plugins.push(platform.plugins);
108
+ }
109
+ }
110
+ else {
111
+ if (platform.plugins instanceof Array) {
112
+ plugins = [plugins, ...platform.plugins];
113
+ }
114
+ else {
115
+ plugins = [plugins, platform.plugins];
116
+ }
117
+ }
118
+ }
119
+ });
120
+ return Object.assign(Object.assign({}, stylelintConfig), { plugins, rules: Object.assign(Object.assign({}, taroRules(platforms)), stylelintConfig.rules) });
121
+ };
package/lib/index.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const stylelint_1 = require("stylelint");
7
+ const rules_1 = __importDefault(require("./rules"));
8
+ const utils_1 = require("./utils");
9
+ const rulesPlugins = Object.keys(rules_1.default).map(ruleName => {
10
+ return (0, stylelint_1.createPlugin)((0, utils_1.nameSpace)(ruleName), rules_1.default[ruleName]);
11
+ });
12
+ exports.default = rulesPlugins;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BACKGROUND_IMAGE = exports.NUMBER = exports.LENGTH_REGEX_SPLIT = exports.LENGTH_REGEX = void 0;
4
+ exports.LENGTH_REGEX = /^-?\d+(\.\d+)?(px|vw|vh|%)?$/i;
5
+ exports.LENGTH_REGEX_SPLIT = /^-?\d+(\.\d+)?(px|vw|vh|%)?(\s+-?\d+(\.\d+)?(px|vw|vh|%)?)*$/i;
6
+ exports.NUMBER = /^-?\d+(\.\d+)?$/;
7
+ exports.BACKGROUND_IMAGE = /(url\(|linear-gradient\()/;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config = {};
4
+ exports.default = config;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constrant_1 = require("./constrant");
4
+ const config = {
5
+ // 禁止的选择器集合
6
+ disAllowedSelectors: {
7
+ 'selector-max-id': 0, // 允许的最大id选择器数量
8
+ 'selector-max-combinators': 0, // 允许的最大组合选择器数量
9
+ 'selector-max-type': 0, // 允许的最大类型选择器数量
10
+ 'selector-max-attribute': 0, // 允许的最大属性选择器数量
11
+ 'selector-max-universal': 0, // 允许的最大通配符选择器数量
12
+ 'selector-pseudo-class-allowed-list': [], // 允许的伪类选择器
13
+ },
14
+ // 支持的属性列表
15
+ supportedProperties: {
16
+ 'margin': [constrant_1.LENGTH_REGEX_SPLIT],
17
+ 'margin-top': [constrant_1.LENGTH_REGEX],
18
+ 'margin-right': [constrant_1.LENGTH_REGEX],
19
+ 'margin-bottom': [constrant_1.LENGTH_REGEX],
20
+ 'margin-left': [constrant_1.LENGTH_REGEX],
21
+ 'padding': [constrant_1.LENGTH_REGEX_SPLIT],
22
+ 'padding-top': [constrant_1.LENGTH_REGEX],
23
+ 'padding-right': [constrant_1.LENGTH_REGEX],
24
+ 'padding-bottom': [constrant_1.LENGTH_REGEX],
25
+ 'padding-left': [constrant_1.LENGTH_REGEX],
26
+ 'width': [constrant_1.LENGTH_REGEX],
27
+ 'height': [constrant_1.LENGTH_REGEX],
28
+ 'min-width': [constrant_1.LENGTH_REGEX],
29
+ 'min-height': [constrant_1.LENGTH_REGEX],
30
+ 'max-width': [constrant_1.LENGTH_REGEX],
31
+ 'max-height': [constrant_1.LENGTH_REGEX],
32
+ 'background': true,
33
+ 'background-color': true,
34
+ 'background-image': [constrant_1.BACKGROUND_IMAGE],
35
+ 'background-size': ['cover', 'contain', constrant_1.LENGTH_REGEX_SPLIT],
36
+ 'background-position': ['center', 'top', 'bottom', 'left', 'right', constrant_1.LENGTH_REGEX_SPLIT],
37
+ 'background-repeat': ['repeat', 'no-repeat', 'repeat-x', 'repeat-y'],
38
+ 'border': true,
39
+ 'border-top': true,
40
+ 'border-right': true,
41
+ 'border-bottom': true,
42
+ 'border-left': true,
43
+ 'border-color': true,
44
+ 'border-top-color': true,
45
+ 'border-right-color': true,
46
+ 'border-bottom-color': true,
47
+ 'border-left-color': true,
48
+ 'border-radius': [constrant_1.LENGTH_REGEX_SPLIT],
49
+ 'border-top-left-radius': [constrant_1.LENGTH_REGEX],
50
+ 'border-top-right-radius': [constrant_1.LENGTH_REGEX],
51
+ 'border-bottom-left-radius': [constrant_1.LENGTH_REGEX],
52
+ 'border-bottom-right-radius': [constrant_1.LENGTH_REGEX],
53
+ 'border-style': true,
54
+ 'border-top-style': true,
55
+ 'border-right-style': true,
56
+ 'border-bottom-style': true,
57
+ 'border-left-style': true,
58
+ 'border-width': [constrant_1.LENGTH_REGEX_SPLIT],
59
+ 'border-top-width': [constrant_1.LENGTH_REGEX],
60
+ 'border-right-width': [constrant_1.LENGTH_REGEX],
61
+ 'border-bottom-width': [constrant_1.LENGTH_REGEX],
62
+ 'border-left-width': [constrant_1.LENGTH_REGEX],
63
+ 'font-size': [constrant_1.LENGTH_REGEX],
64
+ 'font-family': true,
65
+ 'font-style': ['normal', 'italic'],
66
+ 'font-weight': ['normal', 'bold', 'bolder', constrant_1.NUMBER],
67
+ 'line-height': [constrant_1.LENGTH_REGEX],
68
+ 'text-align': ['center', 'left', 'right'],
69
+ 'color': true,
70
+ 'text-decoration': ['none', 'underline', 'line-through', 'overline'],
71
+ 'text-overflow': ['ellipsis', 'clip'],
72
+ 'display': ['flex', 'block'],
73
+ 'flex': true,
74
+ 'flex-direction': ['row', 'column'],
75
+ 'justify-content': ['flex-start', 'flex-end', 'center', 'space-between', 'space-around', 'space-evenly'],
76
+ 'align-items': ['flex-start', 'flex-end', 'center', 'baseline', 'stretch'],
77
+ 'align-content': ['flex-start', 'flex-end', 'center', 'space-between', 'space-around', 'space-evenly'],
78
+ 'flex-wrap': ['nowrap', 'wrap', 'wrap-reverse'],
79
+ 'flex-grow': [constrant_1.NUMBER],
80
+ 'flex-shrink': [constrant_1.NUMBER],
81
+ 'flex-basis': [constrant_1.LENGTH_REGEX, 'auto'],
82
+ 'align-self': ['flex-start', 'flex-end', 'center', 'baseline', 'stretch'],
83
+ 'position': ['absolute', 'relative', 'fixed'],
84
+ 'top': [constrant_1.LENGTH_REGEX],
85
+ 'left': [constrant_1.LENGTH_REGEX],
86
+ 'z-index': [constrant_1.NUMBER],
87
+ 'overflow': ['hidden', 'visible', 'auto'],
88
+ 'opacity': [constrant_1.NUMBER],
89
+ 'transform': true,
90
+ '-webkit-line-clamp': [constrant_1.NUMBER]
91
+ },
92
+ // 关联的插件
93
+ plugins: [
94
+ 'stylelint-taro',
95
+ ],
96
+ // 通用规则
97
+ rules: {
98
+ 'value-no-vendor-prefix': true, // 禁止属性值前缀
99
+ 'property-no-vendor-prefix': true, // 禁止属性前缀
100
+ 'at-rule-allowed-list': [], // 允许的at规则
101
+ 'color-named': ['never'], // 禁止使用命名颜色
102
+ 'declaration-no-important': true, // 禁止使用!important
103
+ 'unit-allowed-list': ['px', 'deg', '%', 'vh', 'vw', 's'], // 允许的单位
104
+ 'function-disallowed-list': ['calc', 'min', 'max', 'clamp'], // 禁止的函数
105
+ }
106
+ };
107
+ exports.default = config;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config = {};
4
+ exports.default = config;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config = {
4
+ // 禁止的选择器集合
5
+ disAllowedSelectors: {
6
+ 'selector-max-id': 0, // 允许的最大id选择器数量
7
+ 'selector-max-combinators': 0, // 允许的最大组合选择器数量
8
+ 'selector-max-type': 0, // 允许的最大类型选择器数量
9
+ 'selector-max-attribute': 0, // 允许的最大属性选择器数量
10
+ 'selector-max-universal': 0, // 允许的最大通配符选择器数量
11
+ 'selector-pseudo-class-allowed-list': ['export', 'root'], // 允许的伪类选择器
12
+ },
13
+ // 支持的属性列表
14
+ supportedProperties: {},
15
+ // 关联的插件
16
+ plugins: [
17
+ 'stylelint-taro'
18
+ ],
19
+ // 通用规则
20
+ rules: {
21
+ 'value-no-vendor-prefix': true, // 禁止属性值前缀
22
+ 'property-no-vendor-prefix': true, // 禁止属性前缀
23
+ 'at-rule-allowed-list': [], // 允许的at规则
24
+ 'color-named': ['never'], // 禁止使用命名颜色
25
+ 'declaration-no-important': true, // 禁止使用!important
26
+ 'unit-allowed-list': ['px', 'rem', 'deg', '%', 'vh', 'vw', 'vmin', 'vmax', 's'], // 允许的单位
27
+ }
28
+ };
29
+ exports.default = config;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.messages = exports.ruleName = void 0;
7
+ const stylelint_1 = __importDefault(require("stylelint"));
8
+ const declarationValueIndex_1 = __importDefault(require("stylelint/lib/utils/declarationValueIndex"));
9
+ const matchesStringOrRegExp_1 = __importDefault(require("stylelint/lib/utils/matchesStringOrRegExp"));
10
+ const optionsMatches_1 = __importDefault(require("stylelint/lib/utils/optionsMatches"));
11
+ const validateObjectWithArrayProps_1 = __importDefault(require("stylelint/lib/utils/validateObjectWithArrayProps"));
12
+ const validateOptions_1 = __importDefault(require("stylelint/lib/utils/validateOptions"));
13
+ const validateTypes_1 = require("stylelint/lib/utils/validateTypes");
14
+ const vendor_1 = __importDefault(require("stylelint/lib/utils/vendor"));
15
+ const utils_1 = require("../../utils");
16
+ exports.ruleName = (0, utils_1.nameSpace)('declaration-property-value-allowed-list');
17
+ exports.messages = stylelint_1.default.utils.ruleMessages(exports.ruleName, {
18
+ rejected: (property, value, platfrom) => (0, utils_1.log)(`"${property}" 暂不支持值 "${value}",受限端: "${platfrom}"`)
19
+ });
20
+ const meta = {
21
+ // TODO: 使用Taro文档的规则
22
+ url: (0, utils_1.taroDocsUrl)('declaration-property-value-allowed-list'),
23
+ };
24
+ const rule = (primary) => {
25
+ return (root, result) => {
26
+ const validOptions = Object.keys(primary).every((key) => {
27
+ if (primary[key]) {
28
+ return (0, validateOptions_1.default)(result, exports.ruleName, {
29
+ actual: primary[key],
30
+ possible: [(0, validateObjectWithArrayProps_1.default)(validateTypes_1.isString, validateTypes_1.isRegExp, validateTypes_1.isBoolean)],
31
+ });
32
+ }
33
+ return true;
34
+ });
35
+ if (!validOptions) {
36
+ return;
37
+ }
38
+ const { intersection } = (0, utils_1.findIntersection)(primary);
39
+ Object.keys(intersection).forEach(key => {
40
+ if (intersection[key] === true) {
41
+ delete intersection[key];
42
+ }
43
+ });
44
+ const propKeys = Object.keys(intersection);
45
+ // 在这里可以添加额外的逻辑
46
+ root.walkDecls(decl => {
47
+ const { prop, value } = decl;
48
+ const unprefixedProp = vendor_1.default.unprefixed(prop);
49
+ const propPatterns = propKeys.filter((key) => (0, matchesStringOrRegExp_1.default)(unprefixedProp, key));
50
+ if (propPatterns.length === 0) {
51
+ return;
52
+ }
53
+ if (propPatterns.some((pattern) => (0, optionsMatches_1.default)(intersection, pattern, value))) {
54
+ return;
55
+ }
56
+ const platforms = [];
57
+ Object.keys(primary).forEach((platform) => {
58
+ if (primary[platform]) {
59
+ if (propPatterns.some((pattern) => {
60
+ return (0, optionsMatches_1.default)(primary[platform], pattern, value) || primary[platform][pattern] === true;
61
+ })) {
62
+ return;
63
+ }
64
+ platforms.push(platform);
65
+ }
66
+ });
67
+ const index = (0, declarationValueIndex_1.default)(decl);
68
+ const endIndex = index + decl.value.length;
69
+ (0, utils_1.report)({
70
+ message: exports.messages.rejected(prop, value, platforms.join(', ')),
71
+ node: decl,
72
+ index,
73
+ endIndex,
74
+ result,
75
+ ruleName: exports.ruleName,
76
+ });
77
+ });
78
+ };
79
+ };
80
+ rule.ruleName = exports.ruleName;
81
+ rule.messages = exports.messages;
82
+ rule.meta = meta;
83
+ exports.default = rule;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const declaration_property_value_allowed_list_1 = __importDefault(require("./declaration-property-value-allowed-list"));
7
+ const no_nested_selectors_1 = __importDefault(require("./no-nested-selectors"));
8
+ const property_allowed_list_1 = __importDefault(require("./property-allowed-list"));
9
+ const rules = {
10
+ 'no-nested-selectors': no_nested_selectors_1.default,
11
+ 'property-allowed-list': property_allowed_list_1.default,
12
+ 'declaration-property-value-allowed-list': declaration_property_value_allowed_list_1.default,
13
+ };
14
+ exports.default = rules;