stylelint-plugin-defensive-css 0.0.2 → 0.0.5

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": "stylelint-plugin-defensive-css",
3
- "version": "0.0.2",
3
+ "version": "0.0.5",
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 'Flex rows must have a `flex-wrap: wrap;` or `flex-wrap: wrap-reverse` declaration.';
16
16
  },
17
17
  vendorPrefixWGrouping() {
18
- return `It's not recommended to group selectors that are meant to work with different browsers. Instead, split them to separate rules.`;
18
+ return `Separate different vendor prefixes into their own rules.`;
19
19
  },
20
20
  });
21
21
 
@@ -8,20 +8,23 @@ const {
8
8
  } = require('../../utils/findShorthandBackgroundRepeat');
9
9
  const { findVendorPrefixes } = require('../../utils/findVendorPrefixes');
10
10
 
11
- const ruleFunction = (_, options) => {
12
- let isLastStyleDeclaration = false;
13
- const backgroundRepeatProps = {
14
- hasBackgroundImage: false,
15
- isMissingBackgroundRepeat: true,
16
- nodeToReport: undefined,
17
- };
18
- const flexWrappingProps = {
19
- isDisplayFlex: false,
20
- isFlexRow: true,
21
- isMissingFlexWrap: true,
22
- nodeToReport: undefined,
23
- };
11
+ const defaultBackgroundRepeatProps = {
12
+ hasBackgroundImage: false,
13
+ isMissingBackgroundRepeat: true,
14
+ nodeToReport: undefined,
15
+ };
16
+ const defaultFlexWrappingProps = {
17
+ isDisplayFlex: false,
18
+ isFlexRow: true,
19
+ isMissingFlexWrap: true,
20
+ nodeToReport: undefined,
21
+ };
24
22
 
23
+ let backgroundRepeatProps = { ...defaultBackgroundRepeatProps };
24
+ let flexWrappingProps = { ...defaultFlexWrappingProps };
25
+ let isLastStyleDeclaration = false;
26
+
27
+ const ruleFunction = (_, options) => {
25
28
  return (root, result) => {
26
29
  const validOptions = stylelint.utils.validateOptions(result, ruleName);
27
30
 
@@ -30,12 +33,9 @@ const ruleFunction = (_, options) => {
30
33
  }
31
34
 
32
35
  root.walkDecls((decl) => {
33
- if (
36
+ isLastStyleDeclaration =
34
37
  JSON.stringify(decl) ===
35
- JSON.stringify(decl.parent.nodes[decl.parent.nodes.length - 1])
36
- ) {
37
- isLastStyleDeclaration = true;
38
- }
38
+ JSON.stringify(decl.parent.nodes[decl.parent.nodes.length - 1]);
39
39
 
40
40
  /* BACKGROUND REPEAT */
41
41
  if (options?.['background-repeat']) {
@@ -55,16 +55,17 @@ const ruleFunction = (_, options) => {
55
55
  backgroundRepeatProps.isMissingBackgroundRepeat = false;
56
56
  }
57
57
 
58
- if (
59
- isLastStyleDeclaration &&
60
- Object.values(backgroundRepeatProps).every((prop) => prop)
61
- ) {
62
- stylelint.utils.report({
63
- message: ruleMessages.backgroundRepeat(),
64
- node: decl.parent,
65
- result,
66
- ruleName,
67
- });
58
+ if (isLastStyleDeclaration) {
59
+ if (Object.values(backgroundRepeatProps).every((prop) => prop)) {
60
+ stylelint.utils.report({
61
+ message: ruleMessages.backgroundRepeat(),
62
+ node: decl.parent,
63
+ result,
64
+ ruleName,
65
+ });
66
+ }
67
+
68
+ backgroundRepeatProps = { ...defaultBackgroundRepeatProps };
68
69
  }
69
70
  }
70
71
 
@@ -95,16 +96,17 @@ const ruleFunction = (_, options) => {
95
96
  flexWrappingProps.isMissingFlexWrap = false;
96
97
  }
97
98
 
98
- if (
99
- isLastStyleDeclaration &&
100
- Object.values(flexWrappingProps).every((prop) => prop)
101
- ) {
102
- stylelint.utils.report({
103
- message: ruleMessages.flexWrapping(),
104
- node: flexWrappingProps.nodeToReport,
105
- result,
106
- ruleName,
107
- });
99
+ if (isLastStyleDeclaration) {
100
+ if (Object.values(flexWrappingProps).every((prop) => prop)) {
101
+ stylelint.utils.report({
102
+ message: ruleMessages.flexWrapping(),
103
+ node: flexWrappingProps.nodeToReport,
104
+ result,
105
+ ruleName,
106
+ });
107
+ }
108
+
109
+ flexWrappingProps = { ...defaultFlexWrappingProps };
108
110
  }
109
111
  }
110
112