From 9c23fd86cd227be487a0785ee464a2da98fb9048 Mon Sep 17 00:00:00 2001 From: Bart Veneman <1536852+bartveneman@users.noreply.github.com> Date: Sat, 30 Dec 2023 00:13:31 +0100 Subject: [PATCH] fix negative tw class names being reported as vendor prefixed selector (#371) closes #348 --- src/__fixtures__/gazelle-20231008.json | 12 ++++++------ src/selectors/complexity.test.js | 10 +++++++--- src/selectors/utils.js | 4 +--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/__fixtures__/gazelle-20231008.json b/src/__fixtures__/gazelle-20231008.json index e75e49a..be1ce83 100644 --- a/src/__fixtures__/gazelle-20231008.json +++ b/src/__fixtures__/gazelle-20231008.json @@ -3,7 +3,7 @@ "sourceLinesOfCode": 29224, "linesOfCode": 45124, "size": 846671, - "complexity": 97705, + "complexity": 97704, "comments": { "total": 4, "size": 1678 @@ -76220,16 +76220,16 @@ "complexity": { "min": 1, "max": 19, - "mean": 3.9728714915986107, + "mean": 3.972777621327326, "mode": 1, "median": 3, "range": 18, - "sum": 42323, + "sum": 42322, "total": 10653, "totalUnique": 19, "unique": { - "1": 2665, - "2": 1132, + "1": 2666, + "2": 1131, "3": 2178, "4": 944, "5": 1242, @@ -86734,7 +86734,7 @@ 2, 1, 1, - 2, + 1, 1, 1, 1, diff --git a/src/selectors/complexity.test.js b/src/selectors/complexity.test.js index da87461..71fb2e1 100644 --- a/src/selectors/complexity.test.js +++ b/src/selectors/complexity.test.js @@ -49,16 +49,20 @@ Complexity('calculates complexity', () => { Complexity('calculates complexity with vendor prefixes', () => { const actual = analyze(` - no-prefix, - fake-webkit, input[type=text]::-webkit-input-placeholder, ::-webkit-scrollbar, .site-header .main-nav:hover>ul>li:nth-child(1) svg, :-moz-any(header, footer) {} + + /* not vendor prefixed */ + no-prefix, + fake-webkit, + .-mt-px, + .-space-x-1 {} `).selectors.complexity assert.equal(actual.unique, { - '1': 2, + '1': 4, '5': 1, '2': 1, '12': 1, diff --git a/src/selectors/utils.js b/src/selectors/utils.js index 21090ab..2112cbc 100644 --- a/src/selectors/utils.js +++ b/src/selectors/utils.js @@ -116,9 +116,7 @@ export function getComplexity(selector) { complexity++ - if (node.type === IdSelector - || node.type === ClassSelector - || node.type === PseudoElementSelector + if (node.type === PseudoElementSelector || node.type === TypeSelector || node.type === PseudoClassSelector ) {