stylelint-taro 4.0.0-beta.78 → 4.0.0-beta.79

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.
Files changed (56) hide show
  1. package/LICENSE +8 -1
  2. package/lib/config.js +121 -0
  3. package/lib/index.js +12 -0
  4. package/lib/platform/constrant.js +7 -0
  5. package/lib/platform/h5.js +4 -0
  6. package/lib/platform/harmony.js +108 -0
  7. package/lib/platform/miniprogram.js +4 -0
  8. package/lib/platform/rn.js +29 -0
  9. package/lib/platform/type.js +2 -0
  10. package/lib/rules/declaration-property-value-allowed-list/index.js +83 -0
  11. package/lib/rules/index.js +14 -0
  12. package/lib/rules/no-nested-selectors/index.js +62 -0
  13. package/lib/rules/property-allowed-list/index.js +81 -0
  14. package/{dist → lib}/utils/index.js +14 -6
  15. package/package.json +46 -26
  16. package/src/config.ts +133 -0
  17. package/src/index.ts +10 -0
  18. package/src/platform/constrant.ts +4 -0
  19. package/src/platform/h5.ts +7 -0
  20. package/src/platform/harmony.ts +109 -0
  21. package/src/platform/miniprogram.ts +7 -0
  22. package/src/platform/rn.ts +31 -0
  23. package/src/platform/type.ts +9 -0
  24. package/src/rules/declaration-property-value-allowed-list/index.ts +96 -0
  25. package/src/rules/index.ts +11 -0
  26. package/src/rules/no-nested-selectors/index.ts +46 -0
  27. package/src/rules/property-allowed-list/index.ts +92 -0
  28. package/src/utils/index.ts +69 -0
  29. package/dist/config.d.ts +0 -1
  30. package/dist/index.cjs.js +0 -257
  31. package/dist/index.cjs.js.map +0 -1
  32. package/dist/index.d.ts +0 -3
  33. package/dist/index.esm.js +0 -253
  34. package/dist/index.esm.js.map +0 -1
  35. package/dist/index.js +0 -10
  36. package/dist/index.js.map +0 -1
  37. package/dist/platform/constrant.d.ts +0 -4
  38. package/dist/platform/h5.d.ts +0 -3
  39. package/dist/platform/harmony.d.ts +0 -3
  40. package/dist/platform/miniprogram.d.ts +0 -3
  41. package/dist/platform/rn.d.ts +0 -3
  42. package/dist/platform/type.d.ts +0 -14
  43. package/dist/rules/declaration-property-value-allowed-list/index.d.ts +0 -7
  44. package/dist/rules/declaration-property-value-allowed-list/index.js +0 -80
  45. package/dist/rules/declaration-property-value-allowed-list/index.js.map +0 -1
  46. package/dist/rules/index.d.ts +0 -6
  47. package/dist/rules/index.js +0 -12
  48. package/dist/rules/index.js.map +0 -1
  49. package/dist/rules/no-nested-selectors/index.d.ts +0 -7
  50. package/dist/rules/no-nested-selectors/index.js +0 -39
  51. package/dist/rules/no-nested-selectors/index.js.map +0 -1
  52. package/dist/rules/property-allowed-list/index.d.ts +0 -7
  53. package/dist/rules/property-allowed-list/index.js +0 -78
  54. package/dist/rules/property-allowed-list/index.js.map +0 -1
  55. package/dist/utils/index.d.ts +0 -11
  56. package/dist/utils/index.js.map +0 -1
package/LICENSE CHANGED
@@ -154,8 +154,15 @@ See `/LICENSE` for details of the license.
154
154
 
155
155
  ==================
156
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.
161
+
162
+ ==================
163
+
157
164
  MIT (weui):
158
- The following files embed [weui](https://github.com/Tencent/weui) MIT:
165
+ The following files embed [stencil-vue2-output-target](https://github.com/Tencent/weui) MIT:
159
166
  `/packages/taro-components/src/components/*.scss`
160
167
  See `/LICENSE.txt` for details of the license.
161
168
 
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|rem|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,108 @@
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-type': 0, // 允许的最大类型选择器数量
9
+ 'selector-max-attribute': 0, // 允许的最大属性选择器数量
10
+ 'selector-max-universal': 0, // 允许的最大通配符选择器数量
11
+ 'selector-pseudo-class-allowed-list': ['before', 'after'], // 允许的伪类选择器
12
+ 'selector-combinator-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', 'none'],
73
+ flex: true,
74
+ 'flex-direction': ['row', 'row-reverse', 'column', 'column-reverse'],
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
+ 'transform-origin': true,
91
+ '-webkit-line-clamp': [constrant_1.NUMBER]
92
+ },
93
+ // 关联的插件
94
+ plugins: [
95
+ 'stylelint-taro',
96
+ ],
97
+ // 通用规则
98
+ rules: {
99
+ 'value-no-vendor-prefix': true, // 禁止属性值前缀
100
+ 'property-no-vendor-prefix': true, // 禁止属性前缀
101
+ 'at-rule-allowed-list': [], // 允许的at规则
102
+ 'color-named': ['never'], // 禁止使用命名颜色
103
+ 'declaration-no-important': false, // 禁止使用!important
104
+ 'unit-allowed-list': ['px', 'deg', '%', 'vh', 'vw', 's', 'rem'], // 允许的单位
105
+ 'function-disallowed-list': ['min', 'max', 'clamp'], // 禁止的函数
106
+ }
107
+ };
108
+ 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;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.messages = exports.ruleName = void 0;
27
+ const stylelint_1 = __importStar(require("stylelint"));
28
+ const utils_1 = require("../../utils");
29
+ exports.ruleName = (0, utils_1.nameSpace)('no-nested-selectors');
30
+ exports.messages = stylelint_1.default.utils.ruleMessages(exports.ruleName, {
31
+ rejected: (selector, platfrom) => (0, utils_1.log)(`"${selector}" 仅能使用单个class选择器,受限端 "${platfrom}"`)
32
+ });
33
+ const meta = {
34
+ // TODO: 使用Taro文档的规则
35
+ url: (0, utils_1.taroDocsUrl)('no-nested-selectors'),
36
+ };
37
+ const rule = (primary) => {
38
+ return (root, result) => {
39
+ const validOptions = stylelint_1.utils.validateOptions(result, exports.ruleName, {
40
+ actual: primary
41
+ });
42
+ if (!validOptions) {
43
+ return;
44
+ }
45
+ const platform = ['harmony', 'rn'];
46
+ root.walkRules(ruleNode => {
47
+ const selector = ruleNode.selector;
48
+ if (!/^[.#]?[a-zA-Z0-9_-]+$/.test(selector)) {
49
+ (0, utils_1.report)({
50
+ ruleName: exports.ruleName,
51
+ result,
52
+ node: ruleNode,
53
+ message: exports.messages.rejected(selector, platform.join(', ')),
54
+ });
55
+ }
56
+ });
57
+ };
58
+ };
59
+ rule.ruleName = exports.ruleName;
60
+ rule.messages = exports.messages;
61
+ rule.meta = meta;
62
+ exports.default = rule;
@@ -0,0 +1,81 @@
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 lodash_1 = __importDefault(require("lodash"));
8
+ const stylelint_1 = __importDefault(require("stylelint"));
9
+ const isCustomProperty_1 = __importDefault(require("stylelint/lib/utils/isCustomProperty"));
10
+ const isStandardSyntaxProperty_1 = __importDefault(require("stylelint/lib/utils/isStandardSyntaxProperty"));
11
+ const matchesStringOrRegExp_1 = __importDefault(require("stylelint/lib/utils/matchesStringOrRegExp"));
12
+ const validateObjectWithArrayProps_1 = __importDefault(require("stylelint/lib/utils/validateObjectWithArrayProps"));
13
+ const validateOptions_1 = __importDefault(require("stylelint/lib/utils/validateOptions"));
14
+ const validateTypes_1 = require("stylelint/lib/utils/validateTypes");
15
+ const vendor_1 = __importDefault(require("stylelint/lib/utils/vendor"));
16
+ const utils_1 = require("../../utils");
17
+ exports.ruleName = (0, utils_1.nameSpace)('property-allowed-list');
18
+ exports.messages = stylelint_1.default.utils.ruleMessages(exports.ruleName, {
19
+ rejected: (property, platfrom) => (0, utils_1.log)(`"${property}" 暂不支持该属性,受限端 "${platfrom}"`)
20
+ });
21
+ const meta = {
22
+ // TODO: 使用Taro文档的规则
23
+ url: (0, utils_1.taroDocsUrl)('property-allowed-list'),
24
+ };
25
+ const rule = (primary) => {
26
+ return (root, result) => {
27
+ const validOptions = Object.keys(primary).every((key) => {
28
+ if (primary[key]) {
29
+ return (0, validateOptions_1.default)(result, exports.ruleName, {
30
+ actual: primary[key],
31
+ possible: [(0, validateObjectWithArrayProps_1.default)(validateTypes_1.isString, validateTypes_1.isRegExp, validateTypes_1.isBoolean)],
32
+ });
33
+ }
34
+ return true;
35
+ });
36
+ if (!validOptions) {
37
+ return;
38
+ }
39
+ const _arr = [];
40
+ Object.keys(primary).forEach(key => {
41
+ _arr.push(...Object.keys(primary[key]));
42
+ });
43
+ const intersectionKeys = lodash_1.default.intersection(_arr);
44
+ // 在这里可以添加额外的逻辑
45
+ root.walkDecls(decl => {
46
+ const prop = decl.prop;
47
+ if (!(0, isStandardSyntaxProperty_1.default)(prop)) {
48
+ return;
49
+ }
50
+ if ((0, isCustomProperty_1.default)(prop)) {
51
+ return;
52
+ }
53
+ // either the prefix or unprefixed version is in the list
54
+ if ((0, matchesStringOrRegExp_1.default)([prop, vendor_1.default.unprefixed(prop)], intersectionKeys)) {
55
+ return;
56
+ }
57
+ const platform = [];
58
+ Object.keys(primary).forEach(key => {
59
+ if (primary[key]) {
60
+ const platformKeys = Object.keys(primary[key]);
61
+ if (platformKeys.length > 0) {
62
+ if (!platformKeys.includes(prop)) {
63
+ platform.push(key);
64
+ }
65
+ }
66
+ }
67
+ });
68
+ (0, utils_1.report)({
69
+ message: exports.messages.rejected(prop, platform.join(', ')),
70
+ word: prop,
71
+ node: decl,
72
+ result,
73
+ ruleName: exports.ruleName,
74
+ });
75
+ });
76
+ };
77
+ };
78
+ rule.ruleName = exports.ruleName;
79
+ rule.messages = exports.messages;
80
+ rule.meta = meta;
81
+ exports.default = rule;
@@ -1,15 +1,24 @@
1
- import stylelint from 'stylelint';
2
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findIntersection = exports.log = exports.report = exports.newMessage = exports.nameSpace = exports.taroDocsUrl = void 0;
4
+ const stylelint_1 = require("stylelint");
3
5
  function taroDocsUrl(_) {
4
6
  return `https://taro-docs.jd.com/docs/`;
5
7
  }
8
+ exports.taroDocsUrl = taroDocsUrl;
6
9
  function nameSpace(ruleName) {
7
10
  // 前缀视个人情况而定
8
11
  return `taro/${ruleName}`;
9
12
  }
13
+ exports.nameSpace = nameSpace;
14
+ function newMessage(ruleName, options) {
15
+ return stylelint_1.utils.ruleMessages(ruleName, options);
16
+ }
17
+ exports.newMessage = newMessage;
10
18
  function report(problem) {
11
- return stylelint.utils.report(problem);
19
+ return stylelint_1.utils.report(problem);
12
20
  }
21
+ exports.report = report;
13
22
  function log(text) {
14
23
  // vscode下不添加颜色
15
24
  if (!process.env.TARO_ENV) {
@@ -18,6 +27,7 @@ function log(text) {
18
27
  return text;
19
28
  // return highlightQuotaValue(text)
20
29
  }
30
+ exports.log = log;
21
31
  function findIntersection(data) {
22
32
  const keys = Object.keys(data);
23
33
  let intersection = {};
@@ -56,6 +66,4 @@ function findIntersection(data) {
56
66
  }
57
67
  return { intersection };
58
68
  }
59
-
60
- export { findIntersection, log, nameSpace, report, taroDocsUrl };
61
- //# sourceMappingURL=index.js.map
69
+ exports.findIntersection = findIntersection;