Skip to content

Commit 167d097

Browse files
authored
feat: update complexity rule to highlight only static block header (#20245)
* feat: update `complexity` rule to highlight only static block header * feat: highlight only static keyword for static blocks
1 parent 2584187 commit 167d097

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

lib/rules/complexity.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ module.exports = {
6868
},
6969

7070
create(context) {
71+
const sourceCode = context.sourceCode;
7172
const option = context.options[0];
7273
let threshold = THRESHOLD_DEFAULT;
7374
let VARIANT = "classic";
@@ -177,12 +178,10 @@ module.exports = {
177178
name = "class field initializer";
178179
} else if (codePath.origin === "class-static-block") {
179180
name = "class static block";
181+
loc = sourceCode.getFirstToken(node).loc;
180182
} else {
181183
name = astUtils.getFunctionNameWithKind(node);
182-
loc = astUtils.getFunctionHeadLoc(
183-
node,
184-
context.sourceCode,
185-
);
184+
loc = astUtils.getFunctionHeadLoc(node, sourceCode);
186185
}
187186

188187
context.report({

tests/lib/rules/complexity.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ ruleTester.run("complexity", rule, {
805805
{
806806
...makeError("Class static block", 4, 3),
807807
column: 11,
808-
endColumn: 39,
808+
endColumn: 17,
809809
},
810810
],
811811
},
@@ -817,7 +817,7 @@ ruleTester.run("complexity", rule, {
817817
{
818818
...makeError("Class static block", 4, 3),
819819
column: 35,
820-
endColumn: 63,
820+
endColumn: 41,
821821
},
822822
],
823823
},
@@ -829,12 +829,12 @@ ruleTester.run("complexity", rule, {
829829
{
830830
...makeError("Class static block", 4, 3),
831831
column: 11,
832-
endColumn: 39,
832+
endColumn: 17,
833833
},
834834
{
835835
...makeError("Class static block", 4, 3),
836836
column: 40,
837-
endColumn: 68,
837+
endColumn: 46,
838838
},
839839
],
840840
},

0 commit comments

Comments
 (0)