Skip to content

Commit 73d0d4b

Browse files
authored
Merge branch 'main' into fix-53391
2 parents 21b7c2e + c333e14 commit 73d0d4b

File tree

4,376 files changed

+1165727
-257768
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,376 files changed

+1165727
-257768
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"allowDeclarations": true
9898
}],
9999
"local/no-double-space": "error",
100-
"local/boolean-trivia": "error",
100+
"local/argument-trivia": "error",
101101
"local/no-in-operator": "error",
102102
"local/simple-indent": "error",
103103
"local/debug-assert": "error",

.github/pr_owners.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ gabritto
1212
jakebailey
1313
DanielRosenwasser
1414
navya9singh
15+
iisaduan

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
matrix:
2222
node-version:
23-
- "19"
23+
- "20"
2424
- "18"
2525
- "16"
2626
- "14"

.github/workflows/new-release-branch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
git add src/compiler/corePublic.ts
3838
git add tests/baselines/reference/api/typescript.d.ts
3939
git add tests/baselines/reference/api/tsserverlibrary.d.ts
40-
git add ./lib
40+
git add --force ./lib
4141
git config user.email "typescriptbot@microsoft.com"
4242
git config user.name "TypeScript Bot"
4343
git commit -m 'Bump version to ${{ github.event.client_payload.package_version }} and LKG'

.github/workflows/set-version.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
git add src/compiler/corePublic.ts
4444
git add tests/baselines/reference/api/typescript.d.ts
4545
git add tests/baselines/reference/api/tsserverlibrary.d.ts
46-
git add ./lib
46+
git add --force ./lib
4747
git config user.email "typescriptbot@microsoft.com"
4848
git config user.name "TypeScript Bot"
4949
git commit -m 'Bump version to ${{ github.event.client_payload.package_version }} and LKG'

.github/workflows/update-lkg.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ jobs:
2525
npx hereby LKG
2626
npm test
2727
git diff
28-
git add ./lib
28+
git add --force ./lib
2929
git commit -m "Update LKG"
3030
git push

Herebyfile.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function createBundler(entrypoint, outfile, taskOptions = {}) {
171171
bundle: true,
172172
outfile,
173173
platform: "node",
174-
target: "es2018",
174+
target: ["es2020", "node14.17"],
175175
format: "cjs",
176176
sourcemap: "linked",
177177
sourcesContent: false,
@@ -616,7 +616,6 @@ export const runTestsAndWatch = task({
616616
});
617617

618618
process.on("SIGINT", endWatchMode);
619-
process.on("SIGKILL", endWatchMode);
620619
process.on("beforeExit", endWatchMode);
621620
watchTestsEmitter.on("rebuild", onRebuild);
622621
testCaseWatcher.on("all", onChange);

package-lock.json

Lines changed: 431 additions & 419 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"tsserver": "./bin/tsserver"
2727
},
2828
"engines": {
29-
"node": ">=12.20"
29+
"node": ">=14.17"
3030
},
3131
"files": [
3232
"bin",
@@ -54,7 +54,7 @@
5454
"@typescript-eslint/eslint-plugin": "^5.33.1",
5555
"@typescript-eslint/parser": "^5.33.1",
5656
"@typescript-eslint/utils": "^5.33.1",
57-
"azure-devops-node-api": "^11.2.0",
57+
"azure-devops-node-api": "^12.0.0",
5858
"chai": "^4.3.7",
5959
"chalk": "^4.1.2",
6060
"chokidar": "^3.5.3",
@@ -83,7 +83,9 @@
8383
"which": "^2.0.2"
8484
},
8585
"overrides": {
86-
"typescript@*": "$typescript"
86+
"typescript@*": "$typescript",
87+
"@octokit/types": "9.0.0",
88+
"@octokit/openapi-types": "16.0.0"
8789
},
8890
"scripts": {
8991
"test": "hereby runtests-parallel --light=false",
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
const { AST_NODE_TYPES, TSESTree, ESLintUtils } = require("@typescript-eslint/utils");
2+
const { createRule } = require("./utils.cjs");
3+
const ts = require("typescript");
4+
5+
const unset = Symbol();
6+
/**
7+
* @template T
8+
* @param {() => T} fn
9+
* @returns {() => T}
10+
*/
11+
function memoize(fn) {
12+
/** @type {T | unset} */
13+
let value = unset;
14+
return () => {
15+
if (value === unset) {
16+
value = fn();
17+
}
18+
return value;
19+
};
20+
}
21+
22+
23+
module.exports = createRule({
24+
name: "argument-trivia",
25+
meta: {
26+
docs: {
27+
description: ``,
28+
recommended: "error",
29+
},
30+
messages: {
31+
argumentTriviaArgumentError: `Tag argument with parameter name`,
32+
argumentTriviaArgumentSpaceError: `There should be 1 space between an argument and its comment`,
33+
argumentTriviaArgumentNameError: `Argument name "{{ got }}" does not match expected name "{{ want }}"`,
34+
},
35+
schema: [],
36+
type: "problem",
37+
fixable: "code",
38+
},
39+
defaultOptions: [],
40+
41+
create(context) {
42+
const sourceCode = context.getSourceCode();
43+
const sourceCodeText = sourceCode.getText();
44+
45+
/** @type {(name: string) => boolean} */
46+
const isSetOrAssert = (name) => name.startsWith("set") || name.startsWith("assert");
47+
/** @type {(node: TSESTree.Node) => boolean} */
48+
const isTrivia = (node) => {
49+
if (node.type === AST_NODE_TYPES.Identifier) {
50+
return node.name === "undefined";
51+
}
52+
53+
if (node.type === AST_NODE_TYPES.Literal) {
54+
// eslint-disable-next-line no-null/no-null
55+
return node.value === null || node.value === true || node.value === false;
56+
}
57+
58+
return false;
59+
};
60+
61+
/** @type {(node: TSESTree.CallExpression | TSESTree.NewExpression) => boolean} */
62+
const shouldIgnoreCalledExpression = (node) => {
63+
if (node.callee && node.callee.type === AST_NODE_TYPES.MemberExpression) {
64+
const methodName = node.callee.property.type === AST_NODE_TYPES.Identifier
65+
? node.callee.property.name
66+
: "";
67+
68+
if (isSetOrAssert(methodName)) {
69+
return true;
70+
}
71+
72+
switch (methodName) {
73+
case "apply":
74+
case "call":
75+
case "equal":
76+
case "stringify":
77+
case "push":
78+
return true;
79+
}
80+
81+
return false;
82+
}
83+
84+
if (node.callee && node.callee.type === AST_NODE_TYPES.Identifier) {
85+
const functionName = node.callee.name;
86+
87+
if (isSetOrAssert(functionName)) {
88+
return true;
89+
}
90+
91+
switch (functionName) {
92+
case "contains":
93+
return true;
94+
}
95+
96+
return false;
97+
}
98+
99+
return false;
100+
};
101+
102+
103+
/** @type {(node: TSESTree.Node, i: number, getSignature: () => ts.Signature | undefined) => void} */
104+
const checkArg = (node, i, getSignature) => {
105+
if (!isTrivia(node)) {
106+
return;
107+
}
108+
109+
const getExpectedName = memoize(() => {
110+
const signature = getSignature();
111+
if (signature) {
112+
const expectedName = signature.parameters[i]?.escapedName;
113+
if (expectedName) {
114+
const name = ts.unescapeLeadingUnderscores(expectedName);
115+
// If a parameter is unused, we prepend an underscore. Ignore this
116+
// so that we can switch between used and unused without modifying code,
117+
// requiring that arugments are tagged with the non-underscored name.
118+
return name.startsWith("_") ? name.slice(1) : name;
119+
}
120+
}
121+
return undefined;
122+
});
123+
124+
const comments = sourceCode.getCommentsBefore(node);
125+
/** @type {TSESTree.Comment | undefined} */
126+
const comment = comments[comments.length - 1];
127+
128+
if (!comment || comment.type !== "Block") {
129+
const expectedName = getExpectedName();
130+
if (expectedName) {
131+
context.report({
132+
messageId: "argumentTriviaArgumentError",
133+
node,
134+
fix: (fixer) => {
135+
return fixer.insertTextBefore(node, `/*${expectedName}*/ `);
136+
}
137+
});
138+
}
139+
else {
140+
context.report({ messageId: "argumentTriviaArgumentError", node });
141+
}
142+
return;
143+
}
144+
145+
const argRangeStart = node.range[0];
146+
const commentRangeEnd = comment.range[1];
147+
const expectedName = getExpectedName();
148+
if (expectedName) {
149+
const got = comment.value;
150+
if (got !== expectedName) {
151+
context.report({
152+
messageId: "argumentTriviaArgumentNameError",
153+
data: { got, want: expectedName },
154+
node: comment,
155+
fix: (fixer) => {
156+
return fixer.replaceText(comment, `/*${expectedName}*/`);
157+
},
158+
});
159+
return;
160+
}
161+
}
162+
163+
const hasNewLine = sourceCodeText.slice(commentRangeEnd, argRangeStart).indexOf("\n") >= 0;
164+
if (argRangeStart !== commentRangeEnd + 1 && !hasNewLine) {
165+
// TODO(jakebailey): range should be whitespace
166+
context.report({
167+
messageId: "argumentTriviaArgumentSpaceError",
168+
node,
169+
fix: (fixer) => {
170+
return fixer.replaceTextRange([commentRangeEnd, argRangeStart], " ");
171+
}
172+
});
173+
}
174+
};
175+
176+
/** @type {(node: TSESTree.CallExpression | TSESTree.NewExpression) => void} */
177+
const checkArgumentTrivia = (node) => {
178+
if (shouldIgnoreCalledExpression(node)) {
179+
return;
180+
}
181+
182+
const getSignature = memoize(() => {
183+
if (context.parserServices?.hasFullTypeInformation) {
184+
const parserServices = ESLintUtils.getParserServices(context);
185+
const checker = parserServices.program.getTypeChecker();
186+
const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);
187+
return checker.getResolvedSignature(tsNode);
188+
}
189+
return undefined;
190+
});
191+
192+
for (let i = 0; i < node.arguments.length; i++) {
193+
const arg = node.arguments[i];
194+
checkArg(arg, i, getSignature);
195+
}
196+
};
197+
198+
return {
199+
CallExpression: checkArgumentTrivia,
200+
NewExpression: checkArgumentTrivia,
201+
};
202+
},
203+
});

0 commit comments

Comments
 (0)