Skip to content

Commit 0729508

Browse files
committedOct 17, 2022
fix(check-param-names): properly handle index offset
1 parent ca91670 commit 0729508

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed
 

‎README.md

+14
Original file line numberDiff line numberDiff line change
@@ -3756,6 +3756,20 @@ declare global {
37563756
*/
37573757
function foo(this: void, arg1: number): void;
37583758
}
3759+
3760+
declare global {
3761+
/**
3762+
* @param r Range is 0-1.
3763+
* @param g Range is 0-1.
3764+
* @param b Range is 0-1.
3765+
*/
3766+
function Color(
3767+
this: void,
3768+
r: float,
3769+
g: float,
3770+
b: float,
3771+
): Color;
3772+
}
37593773
````
37603774

37613775

‎src/rules/checkParamNames.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const validateParameterNames = (
3636
});
3737

3838
let dotted = 0;
39+
let thisOffset = 0;
3940

4041
// eslint-disable-next-line complexity
4142
return paramTags.some(([
@@ -64,9 +65,10 @@ const validateParameterNames = (
6465
return false;
6566
}
6667

67-
let functionParameterName = functionParameterNames[index - dotted];
68+
let functionParameterName = functionParameterNames[index - dotted + thisOffset];
6869
if (functionParameterName === 'this') {
69-
functionParameterName = functionParameterNames[index - dotted + 1];
70+
++thisOffset;
71+
functionParameterName = functionParameterNames[index - dotted + thisOffset];
7072
}
7173

7274
if (!functionParameterName) {

‎test/rules/assertions/checkParamNames.js

+18
Original file line numberDiff line numberDiff line change
@@ -1777,5 +1777,23 @@ export default {
17771777
ignoreReadme: true,
17781778
parser: require.resolve('@typescript-eslint/parser'),
17791779
},
1780+
{
1781+
code: `
1782+
declare global {
1783+
/**
1784+
* @param r Range is 0-1.
1785+
* @param g Range is 0-1.
1786+
* @param b Range is 0-1.
1787+
*/
1788+
function Color(
1789+
this: void,
1790+
r: float,
1791+
g: float,
1792+
b: float,
1793+
): Color;
1794+
}
1795+
`,
1796+
parser: require.resolve('@typescript-eslint/parser'),
1797+
},
17801798
],
17811799
};

0 commit comments

Comments
 (0)
Please sign in to comment.