@alexlit/config-stylelint 60.11.0 → 60.12.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexlit/config-stylelint",
3
- "version": "60.11.0",
3
+ "version": "60.12.1",
4
4
  "private": false,
5
5
  "description": "Stylelint config",
6
6
  "keywords": [
@@ -26,7 +26,8 @@
26
26
  "files": [
27
27
  "README.md",
28
28
  "index.js",
29
- "plugins"
29
+ "plugins",
30
+ "vendor"
30
31
  ],
31
32
  "scripts": {
32
33
  "lint": "cd ../../ && ./scripts/lint.stylelint.sh",
@@ -42,7 +43,7 @@
42
43
  "postcss-html": "^1.8.1",
43
44
  "prettier": "^3.8.3",
44
45
  "stylelint": "17.11.0",
45
- "stylelint-color-format": "^1.1.0",
46
+ "stylelint-color-format": "file:./vendor/stylelint-color-format",
46
47
  "stylelint-config-recommended-vue": "^1.6.1",
47
48
  "stylelint-config-standard": "^40.0.0",
48
49
  "stylelint-config-standard-scss": "^17.0.0",
@@ -1,9 +1,11 @@
1
1
  /**
2
+ * TODO: update plugin from ^1.1.0
3
+ *
2
4
  * @type {import('stylelint').Config}
3
5
  *
4
6
  * @see [stylelint-color-format](https://github.com/filipekiss/stylelint-color-format)
5
7
  */
6
8
  export default {
7
- // plugins: ['stylelint-color-format'], //TODO: update plugin from ^1.1.0
8
- // rules: { 'color-format/format': { format: 'rgb' } },
9
+ plugins: ['stylelint-color-format'],
10
+ rules: { 'color-format/format': { format: 'rgb' } },
9
11
  };
@@ -0,0 +1,5 @@
1
+ const {createPlugin} = require('stylelint');
2
+
3
+ const rules = require('./rules');
4
+
5
+ module.exports = [createPlugin('color-format/format', rules['format'])];
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "stylelint-color-format",
3
+ "version": "1.1.0",
4
+ "description": "Convert Hex colors to either RGBA or HSLA",
5
+ "main": "index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/filipekiss/stylelint-color-format.git"
9
+ },
10
+ "dependencies": {
11
+ "color": "^3.0.0",
12
+ "style-search": "^0.1.0"
13
+ },
14
+ "peerDependencies": {
15
+ "stylelint": ">=8.0.0"
16
+ },
17
+ "devDependencies": {
18
+ "eslint-config-stylelint": "^8.1.0",
19
+ "husky": "^0.14.3",
20
+ "lint-staged": "^7.1.0",
21
+ "np": "^2.20.1",
22
+ "prettier": "^1.12.1",
23
+ "standard-version": "^7.1.0",
24
+ "stylelint": ">=8.0.0",
25
+ "stylelint-test-rule-tape": "^0.2.0",
26
+ "xo": "^0.24.0"
27
+ },
28
+ "keywords": [
29
+ "stylelint",
30
+ "stylelint-plugin",
31
+ "css",
32
+ "sass",
33
+ "scss"
34
+ ],
35
+ "author": "Filipe Kiss <eu@filipekiss.com.br>",
36
+ "license": "MIT",
37
+ "bugs": {
38
+ "url": "https://github.com/filipekiss/stylelint-color-format/issues"
39
+ },
40
+ "homepage": "https://github.com/filipekiss/stylelint-color-format#readme",
41
+ "engines": {
42
+ "node": ">=7"
43
+ }
44
+ }
@@ -0,0 +1,119 @@
1
+ /* eslint-disable unicorn/no-abusive-eslint-disable */
2
+ /* eslint-disable */
3
+ const colorConverter = require('color');
4
+ const styleSearch = require('style-search');
5
+ const stylelint = require('stylelint');
6
+
7
+ const {report, ruleMessages, validateOptions} = stylelint.utils;
8
+
9
+ const ruleName = 'color-format/format';
10
+
11
+ const fixColorFormat = (value, fixer) => {
12
+ if (!value) {
13
+ return value;
14
+ }
15
+
16
+ // Extract the color from value
17
+ const hexMatch = value.match(/#[0-9A-Z]+/gi);
18
+
19
+ if (!hexMatch) {
20
+ return value;
21
+ }
22
+
23
+ const colorTranslation = hexMatch.reduce((table, hexColor) => {
24
+ const color = colorConverter(hexColor);
25
+
26
+ table[hexColor] = fixer.fixTo.includes('hsl')
27
+ ? color.hsl().round().string()
28
+ : color.rgb().string();
29
+
30
+ return table;
31
+ }, {});
32
+
33
+ Object.entries(colorTranslation).forEach(colorTuple => {
34
+ const hexColor = colorTuple[0];
35
+ const fixedColor = colorTuple[1];
36
+
37
+ value = value.replace(hexColor, fixedColor);
38
+ });
39
+
40
+ return value;
41
+ };
42
+
43
+ const messages = ruleMessages(ruleName, {
44
+ custom: message => message,
45
+ rejected: hex => `Unexpected hex color "${hex}"`,
46
+ });
47
+
48
+ const rule = function (actual, options, context) {
49
+ return (root, result) => {
50
+ const validOptions = validateOptions(result, ruleName, {
51
+ actual,
52
+ possible: {
53
+ format: ['rgb', 'rgba', 'hsl', 'hsla'],
54
+ },
55
+ });
56
+
57
+ if (!validOptions) {
58
+ return;
59
+ }
60
+
61
+ root.walkDecls(decl => {
62
+ const declString = decl.toString();
63
+ const fixPositions = [];
64
+
65
+ styleSearch({source: declString, target: '#'}, match => {
66
+ // If there's not a colon, comma, or whitespace character before, we'll assume this is
67
+ // not intended to be a hex color, but is instead something like the
68
+ // hash in a url() argument
69
+ if (!/[:,\s]/.test(declString[match.startIndex - 1])) {
70
+ return;
71
+ }
72
+
73
+ const hexMatch = /^#[0-9A-Z]+/i.exec(
74
+ declString.slice(match.startIndex)
75
+ );
76
+
77
+ if (!hexMatch) {
78
+ return;
79
+ }
80
+
81
+ const hexValue = hexMatch[0];
82
+
83
+ if (context && context.fix) {
84
+ fixPositions.unshift({
85
+ fixTo: actual.format,
86
+ hexValue,
87
+ startIndex: match.startIndex,
88
+ });
89
+
90
+ return;
91
+ }
92
+
93
+ const message =
94
+ actual && actual.message
95
+ ? messages.custom(actual.message)
96
+ : messages.rejected(hexValue);
97
+
98
+ report({
99
+ endIndex: match.endIndex,
100
+ index: match.startIndex,
101
+ message: message,
102
+ node: decl,
103
+ result,
104
+ ruleName,
105
+ });
106
+ });
107
+
108
+ if (fixPositions.length > 0) {
109
+ fixPositions.forEach(fixPosition => {
110
+ decl.value = fixColorFormat(decl.value, fixPosition);
111
+ });
112
+ }
113
+ });
114
+ };
115
+ };
116
+
117
+ rule.ruleName = ruleName;
118
+ rule.messages = messages;
119
+ module.exports = rule;
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ format: require('./color-format/format'),
3
+ };