stylelint-plugin-defensive-css 0.10.4 → 1.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 +6 -0
- package/package.json +23 -15
- package/src/index.js +2 -2
- package/src/rules/use-defensive-css/base.js +4 -12
- package/src/rules/use-defensive-css/index.js +6 -10
- package/src/utils/findCustomProperties.js +1 -5
- package/src/utils/findShorthandBackgroundRepeat.js +1 -5
- package/src/utils/findVendorPrefixes.js +1 -5
package/README.md
CHANGED
|
@@ -8,6 +8,12 @@ A Stylelint plugin to enforce defensive CSS best practices.
|
|
|
8
8
|
|
|
9
9
|
> [Read more about Defensive CSS](https://defensivecss.dev/)
|
|
10
10
|
|
|
11
|
+
## 🚀 Version 1.0.0
|
|
12
|
+
|
|
13
|
+
With the release of version 1.0.0 of the plugin, we now support Stylelint 16.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
11
17
|
## Getting Started
|
|
12
18
|
|
|
13
19
|
> Before getting started with the plugin, you must first have
|
package/package.json
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stylelint-plugin-defensive-css",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "A Stylelint plugin to enforce defensive CSS best practices.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": "./src/index.js",
|
|
6
8
|
"files": [
|
|
7
9
|
"src/**/*.js",
|
|
8
10
|
"!**/**/*.test.js"
|
|
9
11
|
],
|
|
10
12
|
"scripts": {
|
|
11
13
|
"prepare": "husky install",
|
|
12
|
-
"
|
|
14
|
+
"jest": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --runInBand",
|
|
15
|
+
"test": "npm run jest",
|
|
16
|
+
"test:watch": "npm run jest -- --watch"
|
|
13
17
|
},
|
|
14
18
|
"repository": {
|
|
15
19
|
"type": "git",
|
|
@@ -22,33 +26,37 @@
|
|
|
22
26
|
},
|
|
23
27
|
"homepage": "https://github.com/yuschick/stylelint-plugin-defensive-css#readme",
|
|
24
28
|
"engines": {
|
|
25
|
-
"node": ">=
|
|
29
|
+
"node": ">=18.12.0"
|
|
26
30
|
},
|
|
27
31
|
"keywords": [
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
32
|
+
"css",
|
|
33
|
+
"csslint",
|
|
34
|
+
"defensive css",
|
|
35
|
+
"lint",
|
|
36
|
+
"linter",
|
|
37
|
+
"stylelint",
|
|
38
|
+
"stylelint-plugin"
|
|
33
39
|
],
|
|
34
40
|
"peerDependencies": {
|
|
35
|
-
"stylelint": "^14.0.0 || ^15.0.0"
|
|
41
|
+
"stylelint": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
36
42
|
},
|
|
37
43
|
"devDependencies": {
|
|
38
|
-
"@commitlint/cli": "^18.
|
|
39
|
-
"@commitlint/config-conventional": "^18.
|
|
44
|
+
"@commitlint/cli": "^18.4.3",
|
|
45
|
+
"@commitlint/config-conventional": "^18.4.3",
|
|
46
|
+
"cross-env": "^7.0.3",
|
|
40
47
|
"eslint": "^8.35.0",
|
|
41
|
-
"husky": "^8.0.
|
|
48
|
+
"husky": "^8.0.3",
|
|
42
49
|
"jest": "^29.4.3",
|
|
43
50
|
"jest-cli": "^29.4.3",
|
|
44
|
-
"jest-
|
|
51
|
+
"jest-light-runner": "^0.6.0",
|
|
52
|
+
"jest-preset-stylelint": "^7.0.0",
|
|
45
53
|
"lint-staged": "^15.0.2",
|
|
46
54
|
"prettier": "^3.0.3",
|
|
47
55
|
"prettier-eslint": "^16.1.2",
|
|
48
|
-
"stylelint": "^
|
|
56
|
+
"stylelint": "^16.1.0"
|
|
49
57
|
},
|
|
50
58
|
"lint-staged": {
|
|
51
|
-
"**/*.
|
|
59
|
+
"**/*.js|md|json": [
|
|
52
60
|
"eslint",
|
|
53
61
|
"prettier --write"
|
|
54
62
|
]
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import useDefensiveCSS from './rules/use-defensive-css/index.js';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default [useDefensiveCSS];
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import stylelint from 'stylelint';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
export const ruleName = 'plugin/use-defensive-css';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const ruleMessages = stylelint.utils.ruleMessages(ruleName, {
|
|
5
|
+
export const ruleMessages = stylelint.utils.ruleMessages(ruleName, {
|
|
8
6
|
accidentalHover() {
|
|
9
7
|
return 'To prevent accidental hover states on mobile devices, wrap `:hover` selectors inside a `@media (hover: hover) { ...your styles }` query. Learn more: https://defensivecss.dev/tip/hover-media/';
|
|
10
8
|
},
|
|
@@ -28,12 +26,6 @@ const ruleMessages = stylelint.utils.ruleMessages(ruleName, {
|
|
|
28
26
|
},
|
|
29
27
|
});
|
|
30
28
|
|
|
31
|
-
const ruleMeta = {
|
|
29
|
+
export const ruleMeta = {
|
|
32
30
|
url: 'https://github.com/yuschick/stylelint-plugin-defensive-css',
|
|
33
31
|
};
|
|
34
|
-
|
|
35
|
-
module.exports = {
|
|
36
|
-
ruleName,
|
|
37
|
-
ruleMessages,
|
|
38
|
-
ruleMeta,
|
|
39
|
-
};
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import stylelint from 'stylelint';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
findShorthandBackgroundRepeat,
|
|
8
|
-
} = require('../../utils/findShorthandBackgroundRepeat');
|
|
9
|
-
const { findVendorPrefixes } = require('../../utils/findVendorPrefixes');
|
|
10
|
-
const { findCustomProperties } = require('../../utils/findCustomProperties');
|
|
3
|
+
import { ruleName, ruleMessages, ruleMeta } from './base.js';
|
|
4
|
+
import { findShorthandBackgroundRepeat } from '../../utils/findShorthandBackgroundRepeat.js';
|
|
5
|
+
import { findVendorPrefixes } from '../../utils/findVendorPrefixes.js';
|
|
6
|
+
import { findCustomProperties } from '../../utils/findCustomProperties.js';
|
|
11
7
|
|
|
12
8
|
const defaultBackgroundRepeatProps = {
|
|
13
9
|
hasBackgroundImage: false,
|
|
@@ -283,4 +279,4 @@ ruleFunction.ruleName = ruleName;
|
|
|
283
279
|
ruleFunction.messages = ruleMessages;
|
|
284
280
|
ruleFunction.meta = ruleMeta;
|
|
285
281
|
|
|
286
|
-
|
|
282
|
+
export default stylelint.createPlugin(ruleName, ruleFunction);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const expression = /var\(.+?\)/g;
|
|
2
2
|
|
|
3
|
-
function findCustomProperties(value) {
|
|
3
|
+
export function findCustomProperties(value) {
|
|
4
4
|
if (!value) return false;
|
|
5
5
|
|
|
6
6
|
let propertiesFound = [...value.trim().matchAll(expression)];
|
|
@@ -8,7 +8,3 @@ function findCustomProperties(value) {
|
|
|
8
8
|
.map(([property]) => (property.includes(',') ? undefined : property))
|
|
9
9
|
.filter((value) => value);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
module.exports = {
|
|
13
|
-
findCustomProperties,
|
|
14
|
-
};
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
const expression = /\b(repeat|repeat-x|repeat-y|space|round|no-repeat|)\b/g;
|
|
2
2
|
|
|
3
|
-
function findShorthandBackgroundRepeat(value) {
|
|
3
|
+
export function findShorthandBackgroundRepeat(value) {
|
|
4
4
|
return value.match(expression).some((val) => val);
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
findShorthandBackgroundRepeat,
|
|
9
|
-
};
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
const expression = /-\b(moz|ms|o|webkit)\b-/g;
|
|
2
2
|
|
|
3
|
-
function findVendorPrefixes(selector) {
|
|
3
|
+
export function findVendorPrefixes(selector) {
|
|
4
4
|
if (!selector) return false;
|
|
5
5
|
|
|
6
6
|
let prefixesFound = [...selector.trim().matchAll(expression)];
|
|
7
7
|
return prefixesFound.length > 1;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
module.exports = {
|
|
11
|
-
findVendorPrefixes,
|
|
12
|
-
};
|