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 +160 -0
- package/README.md +114 -0
- package/lib/config.js +121 -0
- package/lib/index.js +12 -0
- package/lib/platform/constrant.js +7 -0
- package/lib/platform/h5.js +4 -0
- package/lib/platform/harmony.js +107 -0
- package/lib/platform/miniprogram.js +4 -0
- package/lib/platform/rn.js +29 -0
- package/lib/platform/type.js +2 -0
- package/lib/rules/declaration-property-value-allowed-list/index.js +83 -0
- package/lib/rules/index.js +14 -0
- package/lib/rules/no-nested-selectors/index.js +61 -0
- package/lib/rules/property-allowed-list/index.js +81 -0
- package/lib/utils/index.js +69 -0
- package/package.json +66 -0
- package/src/config.ts +136 -0
- package/src/index.ts +10 -0
- package/src/platform/constrant.ts +4 -0
- package/src/platform/h5.ts +7 -0
- package/src/platform/harmony.ts +108 -0
- package/src/platform/miniprogram.ts +7 -0
- package/src/platform/rn.ts +31 -0
- package/src/platform/type.ts +9 -0
- package/src/rules/declaration-property-value-allowed-list/index.ts +98 -0
- package/src/rules/index.ts +11 -0
- package/src/rules/no-nested-selectors/index.ts +46 -0
- package/src/rules/property-allowed-list/index.ts +94 -0
- package/src/utils/index.ts +69 -0
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
const platform = ['harmony', 'rn'];
|
|
45
|
+
root.walkRules(ruleNode => {
|
|
46
|
+
const selector = ruleNode.selector;
|
|
47
|
+
if (!/^[.#]?[a-zA-Z0-9_-]+$/.test(selector)) {
|
|
48
|
+
(0, utils_1.report)({
|
|
49
|
+
ruleName: exports.ruleName,
|
|
50
|
+
result,
|
|
51
|
+
node: ruleNode,
|
|
52
|
+
message: exports.messages.rejected(selector, platform.join(', ')),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
rule.ruleName = exports.ruleName;
|
|
59
|
+
rule.messages = exports.messages;
|
|
60
|
+
rule.meta = meta;
|
|
61
|
+
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;
|
|
@@ -0,0 +1,69 @@
|
|
|
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");
|
|
5
|
+
function taroDocsUrl(_) {
|
|
6
|
+
return `https://taro-docs.jd.com/docs/`;
|
|
7
|
+
}
|
|
8
|
+
exports.taroDocsUrl = taroDocsUrl;
|
|
9
|
+
function nameSpace(ruleName) {
|
|
10
|
+
// 前缀视个人情况而定
|
|
11
|
+
return `taro/${ruleName}`;
|
|
12
|
+
}
|
|
13
|
+
exports.nameSpace = nameSpace;
|
|
14
|
+
function newMessage(ruleName, options) {
|
|
15
|
+
return stylelint_1.utils.ruleMessages(ruleName, options);
|
|
16
|
+
}
|
|
17
|
+
exports.newMessage = newMessage;
|
|
18
|
+
function report(problem) {
|
|
19
|
+
return stylelint_1.utils.report(problem);
|
|
20
|
+
}
|
|
21
|
+
exports.report = report;
|
|
22
|
+
function log(text) {
|
|
23
|
+
// vscode下不添加颜色
|
|
24
|
+
if (!process.env.TARO_ENV) {
|
|
25
|
+
return text;
|
|
26
|
+
}
|
|
27
|
+
return text;
|
|
28
|
+
// return highlightQuotaValue(text)
|
|
29
|
+
}
|
|
30
|
+
exports.log = log;
|
|
31
|
+
function findIntersection(data) {
|
|
32
|
+
const keys = Object.keys(data);
|
|
33
|
+
let intersection = {};
|
|
34
|
+
if (keys.length > 1) {
|
|
35
|
+
const firstKey = keys[0];
|
|
36
|
+
const firstProps = data[firstKey];
|
|
37
|
+
for (const prop in firstProps) {
|
|
38
|
+
const firstValues = firstProps[prop];
|
|
39
|
+
let commonValues = firstValues || [];
|
|
40
|
+
for (let i = 1; i < keys.length; i++) {
|
|
41
|
+
const currentKey = keys[i];
|
|
42
|
+
const currentProps = data[currentKey];
|
|
43
|
+
const currentValues = currentProps[prop];
|
|
44
|
+
if (Array.isArray(commonValues)) {
|
|
45
|
+
if (Array.isArray(currentValues)) {
|
|
46
|
+
commonValues = commonValues.filter(value => currentValues.includes(value));
|
|
47
|
+
}
|
|
48
|
+
else if (currentValues) {
|
|
49
|
+
commonValues = commonValues.filter(value => currentValues === true || currentValues.includes(value));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if (commonValues === true) {
|
|
53
|
+
commonValues = currentValues || [];
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
commonValues = [];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (commonValues.length > 0) {
|
|
60
|
+
intersection[prop] = commonValues;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
intersection = data[keys[0]];
|
|
66
|
+
}
|
|
67
|
+
return { intersection };
|
|
68
|
+
}
|
|
69
|
+
exports.findIntersection = findIntersection;
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "stylelint-taro",
|
|
3
|
+
"version": "4.0.0-alpha.0",
|
|
4
|
+
"description": "Taro stylelint 规则集合",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib",
|
|
8
|
+
"src",
|
|
9
|
+
"README.md",
|
|
10
|
+
"!**/__tests__"
|
|
11
|
+
],
|
|
12
|
+
"keywords": [
|
|
13
|
+
"css",
|
|
14
|
+
"csslint",
|
|
15
|
+
"lint",
|
|
16
|
+
"linter",
|
|
17
|
+
"stylelint",
|
|
18
|
+
"stylelint-plugin"
|
|
19
|
+
],
|
|
20
|
+
"author": "O2Team",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"lodash": "^4.17.21"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^20.10.4",
|
|
27
|
+
"jest": "^29.3.1",
|
|
28
|
+
"jest-cli": "^29.3.1",
|
|
29
|
+
"jest-environment-node": "^29.5.0",
|
|
30
|
+
"jest-preset-stylelint": "^6.0.0",
|
|
31
|
+
"typescript": "^5.3.3"
|
|
32
|
+
},
|
|
33
|
+
"jest": {
|
|
34
|
+
"clearMocks": true,
|
|
35
|
+
"collectCoverage": false,
|
|
36
|
+
"collectCoverageFrom": [
|
|
37
|
+
"lib/**/*.js"
|
|
38
|
+
],
|
|
39
|
+
"coverageDirectory": "./.coverage/",
|
|
40
|
+
"coverageReporters": [
|
|
41
|
+
"lcov",
|
|
42
|
+
"text"
|
|
43
|
+
],
|
|
44
|
+
"coverageThreshold": {
|
|
45
|
+
"global": {
|
|
46
|
+
"branches": 75,
|
|
47
|
+
"functions": 75,
|
|
48
|
+
"lines": 75,
|
|
49
|
+
"statements": 75
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"setupFiles": [
|
|
53
|
+
"./jest-setup.js"
|
|
54
|
+
],
|
|
55
|
+
"testEnvironment": "node",
|
|
56
|
+
"roots": [
|
|
57
|
+
"lib"
|
|
58
|
+
],
|
|
59
|
+
"testRegex": ".*\\.test\\.js$|lib/.*/__tests__/.*\\.js$"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"dev": "tsc -w",
|
|
63
|
+
"build": "tsc",
|
|
64
|
+
"test": "jest"
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import _ from 'lodash'
|
|
2
|
+
import stylelint from 'stylelint'
|
|
3
|
+
|
|
4
|
+
import h5 from './platform/h5'
|
|
5
|
+
import harmony from './platform/harmony'
|
|
6
|
+
import miniprogram from './platform/miniprogram'
|
|
7
|
+
import rn from './platform/rn'
|
|
8
|
+
import { TaroStylelintConfig } from './platform/type'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
type PlatformType = 'h5' | 'miniprogram' | 'harmony' | 'rn'
|
|
12
|
+
|
|
13
|
+
// 合并平台规则成并集
|
|
14
|
+
function mergeRule (platforms) {
|
|
15
|
+
|
|
16
|
+
const rules = {}
|
|
17
|
+
|
|
18
|
+
// 合并选择器
|
|
19
|
+
platforms.forEach(({ config: platform }) => {
|
|
20
|
+
if (platform.disAllowedSelectors) {
|
|
21
|
+
Object.keys(platform.disAllowedSelectors).forEach(ruleName => {
|
|
22
|
+
const rule = platform.disAllowedSelectors[ruleName]
|
|
23
|
+
if (rules[ruleName]) {
|
|
24
|
+
if (rule instanceof Array) {
|
|
25
|
+
rules[ruleName] = _.intersection(rules[ruleName], rule)
|
|
26
|
+
} else {
|
|
27
|
+
rules[ruleName] = _.merge(rules[ruleName], rule)
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
rules[ruleName] = rule
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
// 支持的属性列表
|
|
37
|
+
let supportPropertiesCheck = false
|
|
38
|
+
const properties = {}
|
|
39
|
+
platforms.forEach(({ name, config }) => {
|
|
40
|
+
if (config.supportedProperties) {
|
|
41
|
+
if (['harmony', 'rn'].includes(name)) {
|
|
42
|
+
supportPropertiesCheck = true
|
|
43
|
+
}
|
|
44
|
+
properties[name] = { ...config.supportedProperties }
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
// 只有harmony和rn支持
|
|
49
|
+
if (supportPropertiesCheck) {
|
|
50
|
+
// rules['taro/no-nested-selectors'] = true
|
|
51
|
+
rules['taro/property-allowed-list'] = properties
|
|
52
|
+
rules['taro/declaration-property-value-allowed-list'] = properties
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 合并规则
|
|
56
|
+
platforms.forEach(({ config }) => {
|
|
57
|
+
if (config.rules) {
|
|
58
|
+
Object.keys(config.rules).forEach(ruleName => {
|
|
59
|
+
const rule = config.rules[ruleName]
|
|
60
|
+
|
|
61
|
+
if (rules[ruleName]) {
|
|
62
|
+
if (rule instanceof Array) {
|
|
63
|
+
rules[ruleName] = _.intersection(rules[ruleName], rule)
|
|
64
|
+
} else if (rule instanceof Boolean) {
|
|
65
|
+
rules[ruleName] = rules[ruleName] || rule
|
|
66
|
+
} else {
|
|
67
|
+
rules[ruleName] = rule
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
rules[ruleName] = rule
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
Object.keys(rules).forEach(ruleName => {
|
|
76
|
+
rules[ruleName] = [
|
|
77
|
+
rules[ruleName],
|
|
78
|
+
{
|
|
79
|
+
severity: 'warning'
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
return rules
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const ruleMap = { harmony, rn, miniprogram, h5 }
|
|
88
|
+
|
|
89
|
+
// 根据平台生成规则
|
|
90
|
+
function taroRules(platforms: PlatformType[] = []) {
|
|
91
|
+
return mergeRule(platforms.map((platform) => ({
|
|
92
|
+
name: platform,
|
|
93
|
+
config: ruleMap[platform]
|
|
94
|
+
})))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function getPlatformConfigs (platforms: PlatformType[]): TaroStylelintConfig[] {
|
|
98
|
+
return platforms.map((platform) => ruleMap[platform]).filter(Boolean)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 到处合并配置的方法
|
|
102
|
+
module.exports = function mergeConfig(platforms: PlatformType[], stylelintConfig: stylelint.Config): stylelint.Config {
|
|
103
|
+
|
|
104
|
+
// 注入环境变量
|
|
105
|
+
process.env.__PLATFORMS__ = platforms.join(',')
|
|
106
|
+
|
|
107
|
+
// 插件合并
|
|
108
|
+
let plugins = stylelintConfig.plugins || []
|
|
109
|
+
const platformConfigs = getPlatformConfigs(platforms)
|
|
110
|
+
platformConfigs.forEach((platform) => {
|
|
111
|
+
if (platform.plugins) {
|
|
112
|
+
if (plugins instanceof Array) {
|
|
113
|
+
if (platform.plugins instanceof Array) {
|
|
114
|
+
plugins.push(...platform.plugins)
|
|
115
|
+
} else {
|
|
116
|
+
plugins.push(platform.plugins)
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
if (platform.plugins instanceof Array) {
|
|
120
|
+
plugins = [plugins, ...platform.plugins]
|
|
121
|
+
} else {
|
|
122
|
+
plugins = [plugins, platform.plugins]
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
...stylelintConfig,
|
|
130
|
+
plugins,
|
|
131
|
+
rules: {
|
|
132
|
+
...taroRules(platforms),
|
|
133
|
+
...stylelintConfig.rules,
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createPlugin } from 'stylelint'
|
|
2
|
+
|
|
3
|
+
import rules from './rules'
|
|
4
|
+
import { nameSpace } from './utils'
|
|
5
|
+
|
|
6
|
+
const rulesPlugins = Object.keys(rules).map(ruleName => {
|
|
7
|
+
return createPlugin(nameSpace(ruleName), rules[ruleName])
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export default rulesPlugins
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { BACKGROUND_IMAGE, LENGTH_REGEX, LENGTH_REGEX_SPLIT, NUMBER } from './constrant'
|
|
2
|
+
import { TaroStylelintConfig } from './type'
|
|
3
|
+
|
|
4
|
+
const config: TaroStylelintConfig = {
|
|
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': [LENGTH_REGEX_SPLIT],
|
|
17
|
+
'margin-top': [LENGTH_REGEX],
|
|
18
|
+
'margin-right': [LENGTH_REGEX],
|
|
19
|
+
'margin-bottom': [LENGTH_REGEX],
|
|
20
|
+
'margin-left': [LENGTH_REGEX],
|
|
21
|
+
'padding': [LENGTH_REGEX_SPLIT],
|
|
22
|
+
'padding-top': [LENGTH_REGEX],
|
|
23
|
+
'padding-right': [LENGTH_REGEX],
|
|
24
|
+
'padding-bottom': [LENGTH_REGEX],
|
|
25
|
+
'padding-left': [LENGTH_REGEX],
|
|
26
|
+
'width': [LENGTH_REGEX],
|
|
27
|
+
'height': [LENGTH_REGEX],
|
|
28
|
+
'min-width': [LENGTH_REGEX],
|
|
29
|
+
'min-height': [LENGTH_REGEX],
|
|
30
|
+
'max-width': [LENGTH_REGEX],
|
|
31
|
+
'max-height': [LENGTH_REGEX],
|
|
32
|
+
'background': true,
|
|
33
|
+
'background-color': true,
|
|
34
|
+
'background-image': [BACKGROUND_IMAGE],
|
|
35
|
+
'background-size': ['cover', 'contain', LENGTH_REGEX_SPLIT],
|
|
36
|
+
'background-position': ['center', 'top', 'bottom', 'left', 'right', 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': [LENGTH_REGEX_SPLIT],
|
|
49
|
+
'border-top-left-radius': [LENGTH_REGEX],
|
|
50
|
+
'border-top-right-radius': [LENGTH_REGEX],
|
|
51
|
+
'border-bottom-left-radius': [LENGTH_REGEX],
|
|
52
|
+
'border-bottom-right-radius': [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': [LENGTH_REGEX_SPLIT],
|
|
59
|
+
'border-top-width': [LENGTH_REGEX],
|
|
60
|
+
'border-right-width': [LENGTH_REGEX],
|
|
61
|
+
'border-bottom-width': [LENGTH_REGEX],
|
|
62
|
+
'border-left-width': [LENGTH_REGEX],
|
|
63
|
+
'font-size': [LENGTH_REGEX],
|
|
64
|
+
'font-family': true,
|
|
65
|
+
'font-style': ['normal', 'italic'],
|
|
66
|
+
'font-weight': ['normal', 'bold', 'bolder', NUMBER],
|
|
67
|
+
'line-height': [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': [NUMBER],
|
|
80
|
+
'flex-shrink': [NUMBER],
|
|
81
|
+
'flex-basis': [LENGTH_REGEX, 'auto'],
|
|
82
|
+
'align-self': ['flex-start', 'flex-end', 'center', 'baseline', 'stretch'],
|
|
83
|
+
'position': ['absolute', 'relative', 'fixed'],
|
|
84
|
+
'top': [LENGTH_REGEX],
|
|
85
|
+
'left': [LENGTH_REGEX],
|
|
86
|
+
'z-index': [NUMBER],
|
|
87
|
+
'overflow': ['hidden', 'visible', 'auto'],
|
|
88
|
+
'opacity': [NUMBER],
|
|
89
|
+
'transform': true,
|
|
90
|
+
'-webkit-line-clamp': [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
|
+
|
|
108
|
+
export default config
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TaroStylelintConfig } from './type'
|
|
2
|
+
|
|
3
|
+
const config: TaroStylelintConfig = {
|
|
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
|
+
// 支持的属性列表
|
|
15
|
+
supportedProperties: {},
|
|
16
|
+
// 关联的插件
|
|
17
|
+
plugins: [
|
|
18
|
+
'stylelint-taro'
|
|
19
|
+
],
|
|
20
|
+
// 通用规则
|
|
21
|
+
rules: {
|
|
22
|
+
'value-no-vendor-prefix': true, // 禁止属性值前缀
|
|
23
|
+
'property-no-vendor-prefix': true, // 禁止属性前缀
|
|
24
|
+
'at-rule-allowed-list': [], // 允许的at规则
|
|
25
|
+
'color-named': ['never'], // 禁止使用命名颜色
|
|
26
|
+
'declaration-no-important': true, // 禁止使用!important
|
|
27
|
+
'unit-allowed-list': ['px', 'rem', 'deg', '%', 'vh', 'vw', 'vmin', 'vmax', 's'], // 允许的单位
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default config
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ConfigPlugins, ConfigRules, CustomSyntax } from 'stylelint'
|
|
2
|
+
|
|
3
|
+
export interface TaroStylelintConfig {
|
|
4
|
+
disAllowedSelectors?: ConfigRules
|
|
5
|
+
supportedProperties?: ConfigRules
|
|
6
|
+
rules?: ConfigRules
|
|
7
|
+
plugins?: ConfigPlugins
|
|
8
|
+
customSyntax?: CustomSyntax
|
|
9
|
+
}
|