stylelint-plugin-defensive-css 0.5.0 → 0.7.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 CHANGED
@@ -23,27 +23,21 @@ npm i stylelint-plugin-defensive-css --save-dev
23
23
  yarn add stylelint-plugin-defensive-css --dev
24
24
  ```
25
25
 
26
- With the plugin installed, the rule(s) can be added to the project's Stylelint
27
- configuration.
28
-
29
- ```json
30
- {
31
- "plugins": ["stylelint-plugin-defensive-css"],
32
- "rules": {
33
- "plugin/use-defensive-css": [true, { "severity": "warning" }]
34
- }
35
- }
36
- ```
26
+ With the plugin installed, the individual rule(s) can be added to the project's
27
+ Stylelint configuration.
37
28
 
38
29
  ## Rules / Options
39
30
 
40
31
  The plugin provides multiple rules that can be toggled on and off as needed.
41
32
 
42
- [Accidental Hover](#accidental-hover) -
43
- [Background-Repeat](#background-repeat) -
44
- [Custom Property Fallbacks](#custom-property-fallbacks) -
45
- [Flex Wrapping](#flex-wrapping) - [Scroll Chaining](#scroll-chaining) -
46
- [Vendor Prefix Grouping](#vendor-prefix-grouping)
33
+ 1. [Accidental Hover](#accidental-hover)
34
+ 2. [Background-Repeat](#background-repeat)
35
+ 3. [Custom Property Fallbacks](#custom-property-fallbacks)
36
+ 4. [Flex Wrapping](#flex-wrapping)
37
+ 5. [Scroll Chaining](#scroll-chaining)
38
+ 6. [Vendor Prefix Grouping](#vendor-prefix-grouping)
39
+
40
+ ---
47
41
 
48
42
  ### Accidental Hover
49
43
 
@@ -221,8 +215,8 @@ div {
221
215
  CSS flexbox is one of the most useful CSS layout features nowadays. It’s
222
216
  tempting to add `display: flex` to a wrapper and have the child items ordered
223
217
  next to each other. The thing is when there is not enough space, those child
224
- items won’t wrap into a new line by default. We need to change that behavior
225
- with `flex-wrap: wrap`.
218
+ items won’t wrap into a new line by default. We need to either change that
219
+ behavior with `flex-wrap: wrap` or explicitly define `nowrap` on the container.
226
220
 
227
221
  Enable this rule in order to require all flex rows to have a flex-wrap value.
228
222
 
@@ -241,6 +235,10 @@ div {
241
235
  display: flex;
242
236
  flex-wrap: wrap;
243
237
  }
238
+ div {
239
+ display: flex;
240
+ flex-wrap: nowrap;
241
+ }
244
242
  div {
245
243
  display: flex;
246
244
  flex-direction: row-reverse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stylelint-plugin-defensive-css",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "A Stylelint plugin to enforce defensive CSS best practices.",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -15,7 +15,7 @@ const ruleMessages = stylelint.utils.ruleMessages(ruleName, {
15
15
  return 'Ensure that any custom properties have a fallback value.';
16
16
  },
17
17
  flexWrapping() {
18
- return 'Flex rows must have a `flex-wrap: wrap;` or `flex-wrap: wrap-reverse` declaration.';
18
+ return 'Flex rows must have a `flex-wrap` value defined.`';
19
19
  },
20
20
  scrollChaining() {
21
21
  return `Containers with an auto or scroll 'overflow' must also have an 'overscroll-behavior' property defined.`;
@@ -33,13 +33,12 @@ let isLastStyleDeclaration = false;
33
33
  let isWrappedInHoverAtRule = false;
34
34
 
35
35
  function traverseParentRules(parent) {
36
- console.log({ parent });
37
36
  if (parent.parent.type === 'root') {
38
37
  return;
39
38
  }
40
39
 
41
40
  if (parent.parent.type === 'atrule') {
42
- if (parent.parent.params.includes('hover: hover')) {
41
+ if (parent.parent.params && parent.parent.params.includes('hover: hover')) {
43
42
  isWrappedInHoverAtRule = true;
44
43
  } else {
45
44
  traverseParentRules(parent.parent);
@@ -64,7 +63,7 @@ const ruleFunction = (_, options) => {
64
63
  if (options?.['accidental-hover']) {
65
64
  const parent = decl.parent;
66
65
  const selector = parent.selector;
67
- const isHoverSelector = selector.includes(':hover');
66
+ const isHoverSelector = selector?.includes(':hover');
68
67
  isWrappedInHoverAtRule = false;
69
68
 
70
69
  if (isHoverSelector) {
@@ -159,7 +158,7 @@ const ruleFunction = (_, options) => {
159
158
  flexWrappingProps.isFlexRow = false;
160
159
  }
161
160
 
162
- if (decl.prop === 'flex-wrap' && decl.value.startsWith('wrap')) {
161
+ if (decl.prop === 'flex-wrap') {
163
162
  flexWrappingProps.isMissingFlexWrap = false;
164
163
  }
165
164