stylelint-config-crisp 1.0.39 → 1.0.41

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.
@@ -20,7 +20,7 @@ jobs:
20
20
  - name: Install NodeJS
21
21
  uses: actions/setup-node@v1
22
22
  with:
23
- node-version: 24.x
23
+ node-version: 26.x
24
24
  registry-url: https://registry.npmjs.org
25
25
 
26
26
  - name: Verify versions
package/README.md CHANGED
@@ -100,6 +100,8 @@ This is the list of configured syntaxes, plugins and rules used by Stylelint Con
100
100
  | :- | :- |
101
101
  | [at-rule-conditional-parentheses](https://github.com/crisp-oss/stylelint-config-crisp/blob/master/rules/at-rule-conditional-parentheses.js) | Enforces parentheses in conditions of at-rules (`@if`, `@elseif`, `@while`) |
102
102
  | [filename-class-match](https://github.com/crisp-oss/stylelint-config-crisp/blob/master/rules/filename-class-match.js) | Ensures that class name is derivated from filename (this rule is only applied to Vue files) |
103
+ | [keyframes-comment](https://github.com/crisp-oss/stylelint-config-crisp/blob/master/rules/keyframes-comment.js) | Requires `// --> KEYFRAMES <--` and an empty line before the first `@keyframes` (including vendor-prefixed variants) in a block, at the same indentation |
104
+ | [media-queries-comment](https://github.com/crisp-oss/stylelint-config-crisp/blob/master/rules/media-queries-comment.js) | Requires `// --> MEDIA-QUERIES <--` and an empty line before the first query (`@media`, `@include mq`, size-based `@container`) in a block, at the same indentation |
103
105
  | [no-inline-colors](https://github.com/crisp-oss/stylelint-config-crisp/blob/master/rules/no-inline-colors.js) | Disallows inline colors (hex, named colors, raw `rgb()` / `hsl()`, Sass color functions and `$color-source--*` variables). Colors must be consumed as CSS variables via `rgb(var(--token))`. Files named `colors.scss`, `codemirror.scss`, `fireworks.scss`, `magic-check.scss` and `reset.scss` are ignored |
104
106
  | [rule-empty-line-before](https://github.com/crisp-oss/stylelint-config-crisp/blob/master/rules/rule-empty-line-before.js) | Requires an empty line before multi-line rules the same way [rule-empty-line-before](https://stylelint.io/user-guide/rules/rule-empty-line-before/) does, but properly handles Sass interpolation `#{}` in selectors |
105
107
  | [selector-class-interpolation](https://github.com/crisp-oss/stylelint-config-crisp/blob/master/rules/selector-class-interpolation.js) | Enforces class selectors to use Sass interpolation (this rule is only applied to Vue files) |
package/index.js CHANGED
@@ -14,6 +14,8 @@ module.exports = {
14
14
  plugins: [
15
15
  "./rules/at-rule-conditional-parentheses",
16
16
  "./rules/filename-class-match",
17
+ "./rules/keyframes-comment",
18
+ "./rules/media-queries-comment",
17
19
  "./rules/no-inline-colors",
18
20
  "./rules/rule-empty-line-before",
19
21
  "./rules/selector-class-interpolation",
@@ -131,6 +133,8 @@ module.exports = {
131
133
  // Crisp rules
132
134
  "crisp/at-rule-conditional-parentheses": true,
133
135
  "crisp/filename-class-match": true,
136
+ "crisp/keyframes-comment": true,
137
+ "crisp/media-queries-comment": true,
134
138
  "crisp/no-inline-colors": true,
135
139
  "crisp/rule-empty-line-before": true,
136
140
  "crisp/selector-class-interpolation": true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stylelint-config-crisp",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "description": "Custom Stylelint Rules for Crisp",
5
5
  "author": "Crisp IM SAS",
6
6
  "main": "index.js",
@@ -12,6 +12,9 @@
12
12
  "bugs": {
13
13
  "url": "https://github.com/crisp-oss/stylelint-config-crisp/issues"
14
14
  },
15
+ "scripts": {
16
+ "test": "node --test"
17
+ },
15
18
  "dependencies": {
16
19
  "@stylistic/stylelint-config": "2.0.0",
17
20
  "postcss-html": "1.8.0",
@@ -0,0 +1,7 @@
1
+ const sectionCommentRule = require("./utils/section-comment-rule");
2
+
3
+ module.exports = sectionCommentRule(
4
+ "crisp/keyframes-comment",
5
+ "KEYFRAMES",
6
+ (atRule) => /^(?:-[a-z]+-)?keyframes$/i.test(atRule.name)
7
+ );
@@ -0,0 +1,28 @@
1
+ const sectionCommentRule = require("./utils/section-comment-rule");
2
+
3
+ const SIZE_QUERY_PATTERN = /(?:max|min)-(?:width|height)|(?:width|height)\s*[<>]=?/;
4
+
5
+ // Include all media queries and retain support for size-based container queries.
6
+ function isBreakpointAtRule(atRule) {
7
+ const name = atRule.name.toLowerCase();
8
+
9
+ if (name === "media") {
10
+ return true;
11
+ }
12
+
13
+ if (name === "include") {
14
+ return /^mq\s*\(/.test(atRule.params.trim());
15
+ }
16
+
17
+ if (name === "container") {
18
+ return SIZE_QUERY_PATTERN.test(atRule.params);
19
+ }
20
+
21
+ return false;
22
+ }
23
+
24
+ module.exports = sectionCommentRule(
25
+ "crisp/media-queries-comment",
26
+ "MEDIA-QUERIES",
27
+ isBreakpointAtRule
28
+ );
@@ -0,0 +1,121 @@
1
+ const stylelint = require("stylelint");
2
+
3
+ // Require one section heading before the first matching at-rule in each block.
4
+ module.exports = (ruleName, heading, isSectionAtRule) => {
5
+ const text = `--> ${heading} <--`;
6
+ const commentLine = `// ${text}`;
7
+ const looseHeading = heading.replace(/-/g, "[-\\s]");
8
+ const looseCommentPattern = new RegExp(`^\\s*(?:-->\\s*)?${looseHeading}(?:\\s*<--)?\\s*$`, "i");
9
+ const messages = stylelint.utils.ruleMessages(ruleName, {
10
+ expected: `Expected "${commentLine}" comment before the first section at-rule`,
11
+ expectedIndent: `Expected "${commentLine}" comment to match at-rule indentation`,
12
+ expectedEmptyLine: `Expected an empty line after "${commentLine}"`
13
+ });
14
+
15
+ const ruleFunction = (primaryOption) => {
16
+ return (root, result) => {
17
+ if (!stylelint.utils.validateOptions(result, ruleName, {
18
+ actual: primaryOption,
19
+ possible: [true]
20
+ })) {
21
+ return;
22
+ }
23
+
24
+ root.walkAtRules((atRule) => {
25
+ if (!isSectionAtRule(atRule) || hasPreviousSectionAtRule(atRule, isSectionAtRule)) {
26
+ return;
27
+ }
28
+
29
+ // Nested queries inherit the heading of the containing section.
30
+ let parent = atRule.parent;
31
+
32
+ while (parent) {
33
+ if (parent.type === "atrule" && isSectionAtRule(parent)) {
34
+ return;
35
+ }
36
+
37
+ parent = parent.parent;
38
+ }
39
+
40
+ const indent = getIndent(atRule);
41
+ const previousNode = atRule.prev();
42
+ const isComment = previousNode && previousNode.type === "comment";
43
+ const isExactComment = isComment &&
44
+ previousNode.text === text &&
45
+ previousNode.raws.inline === true &&
46
+ previousNode.raws.left === " " &&
47
+ !previousNode.raws.right;
48
+ const newline = root.source.input.css.includes("\r\n") ? "\r\n" : "\n";
49
+ const report = (message, fix, node = atRule) => {
50
+ stylelint.utils.report({ ruleName, result, node, message, fix });
51
+ };
52
+
53
+ if (!isExactComment) {
54
+ report(messages.expected, () => {
55
+ const raws = { inline: true, left: " ", right: "", text };
56
+
57
+ if (isComment && looseCommentPattern.test(previousNode.text)) {
58
+ previousNode.text = text;
59
+ Object.assign(previousNode.raws, raws);
60
+ setIndent(previousNode, indent, newline);
61
+ } else {
62
+ atRule.parent.insertBefore(atRule, {
63
+ text,
64
+ source: atRule.source,
65
+ raws: { ...raws, before: atRule.raws.before || "" }
66
+ });
67
+ }
68
+
69
+ atRule.raws.before = `${newline}${newline}${indent}`;
70
+ });
71
+
72
+ return;
73
+ }
74
+
75
+ if (getIndent(previousNode) !== indent) {
76
+ report(messages.expectedIndent, () => {
77
+ setIndent(previousNode, indent, newline);
78
+ }, previousNode);
79
+ }
80
+
81
+ if (!/^(?:\r?\n)[ \t]*(?:\r?\n)[ \t]*$/.test(atRule.raws.before || "")) {
82
+ report(messages.expectedEmptyLine, () => {
83
+ atRule.raws.before = `${newline}${newline}${indent}`;
84
+ });
85
+ }
86
+ });
87
+ };
88
+ };
89
+
90
+ ruleFunction.ruleName = ruleName;
91
+ ruleFunction.messages = messages;
92
+ ruleFunction.meta = { fixable: true };
93
+
94
+ return stylelint.createPlugin(ruleName, ruleFunction);
95
+ };
96
+
97
+ function hasPreviousSectionAtRule(atRule, isSectionAtRule) {
98
+ let previousNode = atRule.prev();
99
+
100
+ while (previousNode) {
101
+ if (previousNode.type === "atrule" && isSectionAtRule(previousNode)) {
102
+ return true;
103
+ }
104
+
105
+ previousNode = previousNode.prev();
106
+ }
107
+
108
+ return false;
109
+ }
110
+
111
+ function getIndent(node) {
112
+ return (node.raws.before || "").match(/(?:^|\r?\n)([ \t]*)$/)?.[1] || "";
113
+ }
114
+
115
+ function setIndent(node, indent, newline) {
116
+ const before = node.raws.before || "";
117
+
118
+ node.raws.before = /(?:^|\n)[ \t]*$/.test(before)
119
+ ? before.replace(/[ \t]*$/, indent)
120
+ : `${newline}${indent}`;
121
+ }