Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
ea72ed8
Add config
jakebailey Aug 25, 2023
e72cade
[generated] eslint --fix
jakebailey Aug 25, 2023
c9ed25d
Manual fixes
jakebailey Aug 25, 2023
4089625
Date.now
jakebailey Aug 25, 2023
85b689b
No object reduce
jakebailey Aug 25, 2023
57b777e
Buffer.from
jakebailey Aug 25, 2023
a65798d
Set
jakebailey Aug 25, 2023
61f5fb1
Merge branch 'main' into eslint-plugin-unicorn
jakebailey Sep 1, 2023
62206d9
Enable lint rule now that helper is gone
jakebailey Sep 1, 2023
d575268
Drop rule, I'm not gonna fix 240 of these by hand
jakebailey Sep 1, 2023
a6a82bf
Don't new Array + join for padding
jakebailey Sep 1, 2023
c8263be
Fix compile err
jakebailey Sep 5, 2023
db0344e
Merge branch 'main' into eslint-plugin-unicorn
jakebailey Sep 6, 2023
a834ea6
Fix lint
jakebailey Sep 6, 2023
8f707b5
Merge branch 'main' into eslint-plugin-unicorn
jakebailey Dec 11, 2023
18f411d
Bump and fix
jakebailey Dec 11, 2023
2145843
Merge branch 'main' into eslint-plugin-unicorn
jakebailey Jan 20, 2024
fef5532
Fix lint
jakebailey Jan 20, 2024
b1d2b24
Bump
jakebailey Jan 20, 2024
1764b8e
Classify
jakebailey Jan 20, 2024
695ed0f
More triage
jakebailey Jan 20, 2024
74b6550
More triage
jakebailey Jan 20, 2024
4681bc0
More triage
jakebailey Jan 20, 2024
7771ddf
More triage
jakebailey Jan 20, 2024
844233b
More triage
jakebailey Jan 20, 2024
33366b2
More triage
jakebailey Jan 20, 2024
200ee8b
More triage
jakebailey Jan 20, 2024
3da23d0
More triage
jakebailey Jan 20, 2024
eb7ba9f
More triage
jakebailey Jan 20, 2024
c251a2b
number literal
jakebailey Jan 20, 2024
12ad192
More triage
jakebailey Jan 20, 2024
ee0f535
More triage
jakebailey Jan 20, 2024
a079fd6
More triage
jakebailey Jan 21, 2024
5fae6cc
Merge branch 'main' into eslint-plugin-unicorn
jakebailey Mar 19, 2024
5ac2b65
disable
jakebailey Mar 19, 2024
10fafc0
new
jakebailey Mar 19, 2024
ce92c95
fmt
jakebailey Mar 19, 2024
2a4ac4e
Merge branch 'main' into eslint-plugin-unicorn
jakebailey Apr 22, 2024
e0ae3ff
fix lints
jakebailey Apr 22, 2024
f2853a1
update now that it doesn't crash
jakebailey Apr 22, 2024
c1814d3
Merge branch 'main' into eslint-plugin-unicorn
jakebailey Jun 27, 2024
e0e8eaa
Drop raw
jakebailey Jun 27, 2024
571bd74
Fix some
jakebailey Jun 28, 2024
5998579
structuredClone
jakebailey Jun 28, 2024
e35981f
Merge branch 'main' into eslint-plugin-unicorn
jakebailey Aug 4, 2024
37c2dca
Remove cast
jakebailey Aug 4, 2024
10fc6fa
Fix more
jakebailey Aug 4, 2024
ceb0ebb
Merge branch 'main' into eslint-plugin-unicorn
jakebailey Aug 13, 2024
9bcfd34
Fix lock
jakebailey Aug 13, 2024
507fffc
Merge branch 'main' into eslint-plugin-unicorn
jakebailey Aug 14, 2024
da0907f
Merge branch 'main' into eslint-plugin-unicorn
jakebailey Apr 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"plugin:@typescript-eslint/stylistic"
],
"plugins": [
"@typescript-eslint", "no-null", "eslint-plugin-local", "simple-import-sort"
"@typescript-eslint", "no-null", "eslint-plugin-local", "simple-import-sort", "unicorn"
],
"ignorePatterns": [
"**/node_modules/**",
Expand Down Expand Up @@ -123,6 +123,27 @@
"local/no-keywords": "error",
"local/jsdoc-format": "error",

// eslint-plugin-unicorn
"unicorn/prefer-includes": "error",
"unicorn/new-for-builtins": "error",
"unicorn/prefer-logical-operator-over-ternary": "error",
"unicorn/no-instanceof-array": "error",
"unicorn/prefer-optional-catch-binding": "error",
"unicorn/require-array-join-separator": "error",
"unicorn/throw-new-error": "error",
"unicorn/no-useless-spread": "error",
"unicorn/no-useless-fallback-in-spread": "error",
"unicorn/prefer-modern-math-apis": "error",
"unicorn/prefer-array-find": "error",
"unicorn/prefer-array-some": "error",
"unicorn/prefer-date-now": "error",
"unicorn/prefer-object-from-entries": "error",
"unicorn/no-new-buffer": "error",
"unicorn/prefer-set-has": "error",
// TODO(jakebailey): Require manual fixups
// "unicorn/prefer-string-slice": "error",
// "unicorn/prefer-string-trim-start-end": "error", // check perf vs helper

// eslint-plugin-no-null
"no-null/no-null": "error",

Expand Down
1,156 changes: 1,150 additions & 6 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"eslint-plugin-local": "^1.0.0",
"eslint-plugin-no-null": "^1.0.2",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-unicorn": "^48.0.1",
"fast-xml-parser": "^4.0.11",
"glob": "^8.1.0",
"hereby": "^1.6.4",
Expand Down
2 changes: 1 addition & 1 deletion scripts/browserIntegrationTest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ try {
// @ts-ignore-error
playwright = await import("playwright");
}
catch (error) {
catch {
throw new Error("Playwright is expected to be installed manually before running this script");
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/errorCheck.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function checkErrorBaselines() {
let g;
while (g = errRegex.exec(baseline)) {
const errCode = +g[1];
const msg = keys.filter(k => messages[k].code === errCode)[0];
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just seems like a weird pattern in general. Particularly since filter doesn't short-circuit.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't disagree, I didn't write it, but I am fixing it 😅

const msg = keys.find(k => messages[k].code === errCode);
messages[msg].seen = true;
}
});
Expand Down
6 changes: 3 additions & 3 deletions scripts/eslint/rules/no-keywords.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = createRule({
defaultOptions: [],

create(context) {
const keywords = [
const keywords = new Set([
"Undefined",
"undefined",
"Boolean",
Expand All @@ -32,10 +32,10 @@ module.exports = createRule({
"Number",
"number",
"any",
];
]);

/** @type {(name: string) => boolean} */
const isKeyword = name => keywords.includes(name);
const isKeyword = name => keywords.has(name);

/** @type {(node: TSESTree.Identifier) => void} */
const report = node => {
Expand Down
2 changes: 1 addition & 1 deletion scripts/eslint/rules/only-arrow-functions.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = createRule({

create(context, [{ allowNamedFunctions, allowDeclarations }]) {
/** @type {(node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression) => boolean} */
const isThisParameter = node => !!node.params.length && !!node.params.find(param => param.type === AST_NODE_TYPES.Identifier && param.name === "this");
const isThisParameter = node => node.params.some(param => param.type === AST_NODE_TYPES.Identifier && param.name === "this");

/** @type {(node: TSESTree.Node) => boolean} */
const isMethodType = node => {
Expand Down
2 changes: 1 addition & 1 deletion scripts/failed-tests.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class FailedTestsReporter extends Mocha.reporters.Base {
try {
reporter = require(reporterOptions.reporter);
}
catch (_) {
catch {
reporter = require(path.resolve(process.cwd(), reporterOptions.reporter));
}
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/find-unused-diganostic-messages.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ startOfDiags.split(EOL).forEach(line => {
execSync(`grep -rnw 'src' -e 'Diagnostics.${diagName}'`).toString();
process.stdout.write(".");
}
catch (error) {
catch {
missingNames.push(diagName);
process.stdout.write("x");
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/update-experimental-branches.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function main() {
owner: "Microsoft",
repo: "TypeScript",
})).data.filter(i => !!i.pull_request).map(i => i.number);
if (triggeredPR && !prnums.some(n => n === +triggeredPR)) {
if (triggeredPR && !prnums.includes(+triggeredPR)) {
return; // Only have work to do for enlisted PRs
}
console.log(`Performing experimental branch updating and merging for pull requests ${prnums.join(", ")}`);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ function getBuildInfo(state: BuilderProgramState, bundle: BundleBuildInfo | unde

function toFileIdListId(set: ReadonlySet<Path>): ProgramBuildInfoFileIdListId {
const fileIds = arrayFrom(set.keys(), toFileId).sort(compareValues);
const key = fileIds.join();
const key = fileIds.join(",");
let fileIdListId = fileNamesToFileIdListId?.get(key);
if (fileIdListId === undefined) {
(fileIdsList ||= []).push(fileIds);
Expand Down Expand Up @@ -1783,7 +1783,7 @@ export function toBuilderFileEmit(value: ProgramBuilderInfoFilePendingEmit, full

/** @internal */
export function toProgramEmitPending(value: ProgramBuildInfoBundlePendingEmit, options: CompilerOptions | undefined): BuilderFileEmit | undefined {
return !value ? getBuilderFileEmit(options || {}) : value;
return value || getBuilderFileEmit(options || {});
}

/** @internal */
Expand Down
9 changes: 6 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11722,6 +11722,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// up recursively calling getTypeOfAlias, causing a stack overflow.
links.type = exportSymbol?.declarations && isDuplicatedCommonJSExport(exportSymbol.declarations) && symbol.declarations!.length ? getFlowTypeFromCommonJSExport(exportSymbol)
: isDuplicatedCommonJSExport(symbol.declarations) ? autoType
// eslint-disable-next-line unicorn/prefer-logical-operator-over-ternary
: declaredType ? declaredType
: getSymbolFlags(targetSymbol) & SymbolFlags.Value ? getTypeOfSymbol(targetSymbol)
: errorType;
Expand Down Expand Up @@ -14364,7 +14365,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
const writeType = getWriteTypeOfSymbol(prop);
if (writeTypes || writeType !== type) {
writeTypes = append(!writeTypes ? propTypes.slice() : writeTypes, writeType);
writeTypes = append(writeTypes ?? propTypes.slice(), writeType);
}
else if (type !== firstType) {
checkFlags |= CheckFlags.HasNonUniformType;
Expand Down Expand Up @@ -14641,6 +14642,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// the intersected key type, we just use unknownType for the key type as nothing actually depends on the
// keyType property of the returned IndexInfo.
return applicableInfos ? createIndexInfo(unknownType, getIntersectionType(map(applicableInfos, info => info.type)), reduceLeft(applicableInfos, (isReadonly, info) => isReadonly && info.isReadonly, /*initial*/ true)) :
// eslint-disable-next-line unicorn/prefer-logical-operator-over-ternary
applicableInfo ? applicableInfo :
stringIndexInfo && isApplicableIndexType(keyType, stringType) ? stringIndexInfo :
undefined;
Expand Down Expand Up @@ -16369,7 +16371,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return readonly ? globalReadonlyArrayType : globalArrayType;
}
const memberIds = mapDefined(namedMemberDeclarations, node => node ? getNodeId(node) : undefined);
const key = map(elementFlags, f => f & ElementFlags.Required ? "#" : f & ElementFlags.Optional ? "?" : f & ElementFlags.Rest ? "." : "*").join() +
const key = map(elementFlags, f => f & ElementFlags.Required ? "#" : f & ElementFlags.Optional ? "?" : f & ElementFlags.Rest ? "." : "*").join(",") +
(readonly ? "R" : "") +
(memberIds.length ? "," + memberIds.join(",") : "");
let type = tupleTypes.get(key);
Expand Down Expand Up @@ -46412,7 +46414,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
else {
const copy = createSymbol(SymbolFlags.Signature, InternalSymbolName.Index);
copy.declarations = mapDefined(infos, i => i.declaration);
copy.parent = type.aliasSymbol ? type.aliasSymbol : type.symbol ? type.symbol : getSymbolAtLocation(copy.declarations[0].parent);
copy.parent = type.aliasSymbol ?? type.symbol ?? getSymbolAtLocation(copy.declarations[0].parent);
symbolLinks.filteredIndexSymbolCache.set(nodeListId, copy);
return copy;
}
Expand Down Expand Up @@ -49858,6 +49860,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

function getEffectivePropertyNameForPropertyNameNode(node: PropertyName) {
const name = getPropertyNameForPropertyNameNode(node);
// eslint-disable-next-line unicorn/prefer-logical-operator-over-ternary
return name ? name :
isComputedPropertyName(node) ? tryGetNameFromType(getTypeOfExpression(node.expression)) : undefined;
}
Expand Down
12 changes: 5 additions & 7 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2481,7 +2481,7 @@ export function convertToTSConfig(configParseResult: ParsedCommandLine, configFi
version: undefined,
},
watchOptions: watchOptionMap && optionMapToObject(watchOptionMap),
references: map(configParseResult.projectReferences, r => ({ ...r, path: r.originalPath ? r.originalPath : "", originalPath: undefined })),
references: map(configParseResult.projectReferences, r => ({ ...r, path: r.originalPath || "", originalPath: undefined })),
files: length(files) ? files : undefined,
...(configParseResult.options.configFile?.configFileSpecs ? {
include: filterSameAsDefaultInclude(configParseResult.options.configFile.configFileSpecs.validatedIncludeSpecs),
Expand All @@ -2493,10 +2493,8 @@ export function convertToTSConfig(configParseResult: ParsedCommandLine, configFi
}

/** @internal */
export function optionMapToObject(optionMap: Map<string, CompilerOptionsValue>): object {
return {
...arrayFrom(optionMap.entries()).reduce((prev, cur) => ({ ...prev, [cur[0]]: cur[1] }), {}),
};
export function optionMapToObject(optionMap: Map<string, CompilerOptionsValue>) {
return Object.fromEntries(optionMap.entries());
}

function filterSameAsDefaultInclude(specs: readonly string[] | undefined) {
Expand Down Expand Up @@ -2615,7 +2613,7 @@ export function getCompilerOptionsDiffValue(options: CompilerOptions, newLine: s
return getOverwrittenDefaultOptions();

function makePadding(paddingLength: number): string {
return Array(paddingLength + 1).join(" ");
return new Array(paddingLength + 1).join(" ");

This comment was marked as resolved.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though really I don't know why this isn't just .repeat.

}

function getOverwrittenDefaultOptions() {
Expand Down Expand Up @@ -2659,7 +2657,7 @@ export function generateTSConfig(options: CompilerOptions, fileNames: readonly s
return writeConfigurations();

function makePadding(paddingLength: number): string {
return Array(paddingLength + 1).join(" ");
return new Array(paddingLength + 1).join(" ");
}

function isAllowedOptionForOutput({ category, name, isCommandLineOnly }: CommandLineOption): boolean {
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
}

function computeColumnWidths(height: number) {
const columns: number[] = fill(Array(height), 0);
const columns: number[] = fill(new Array(height), 0);
for (const node of nodes) {
columns[node.level] = Math.max(columns[node.level], node.text.length);
}
Expand Down Expand Up @@ -1121,9 +1121,9 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
function renderGraph() {
const columnCount = columnWidths.length;
const laneCount = nodes.reduce((x, n) => Math.max(x, n.lane), 0) + 1;
const lanes: string[] = fill(Array(laneCount), "");
const grid: (FlowGraphNode | undefined)[][] = columnWidths.map(() => Array(laneCount));
const connectors: Connection[][] = columnWidths.map(() => fill(Array(laneCount), 0));
const lanes: string[] = fill(new Array(laneCount), "");
const grid: (FlowGraphNode | undefined)[][] = columnWidths.map(() => new Array(laneCount));
const connectors: Connection[][] = columnWidths.map(() => fill(new Array(laneCount), 0));

// build connectors
for (const node of nodes) {
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2241,6 +2241,7 @@ function loadEntrypointsFromExportMap(
});
}
else {
// eslint-disable-next-line unicorn/prefer-set-has
const partsAfterFirst = getPathComponents(target).slice(2);
if (partsAfterFirst.includes("..") || partsAfterFirst.includes(".") || partsAfterFirst.includes("node_modules")) {
return false;
Expand Down Expand Up @@ -2675,6 +2676,7 @@ function getLoadModuleFromTargetImportOrExport(extensions: Extensions, state: Mo
return toSearchResult(/*value*/ undefined);
}
const parts = pathIsRelative(target) ? getPathComponents(target).slice(1) : getPathComponents(target);
// eslint-disable-next-line unicorn/prefer-set-has
const partsAfterFirst = parts.slice(1);
if (partsAfterFirst.includes("..") || partsAfterFirst.includes(".") || partsAfterFirst.includes("node_modules")) {
if (state.traceEnabled) {
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10437,7 +10437,7 @@ export function processCommentPragmas(context: PragmaContext, sourceText: string
for (const pragma of pragmas) {
if (context.pragmas.has(pragma.name)) {
const currentValue = context.pragmas.get(pragma.name);
if (currentValue instanceof Array) {
if (Array.isArray(currentValue)) {
currentValue.push(pragma.args);
}
else {
Expand Down Expand Up @@ -10497,7 +10497,7 @@ export function processPragmasIntoFields(context: PragmaContext, reportDiagnosti
break;
}
case "amd-module": {
if (entryOrList instanceof Array) {
if (Array.isArray(entryOrList)) {
for (const entry of entryOrList) {
if (context.moduleName) {
// TODO: It's probably fine to issue this diagnostic on all instances of the pragma
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/perfLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ try {
// It may also return undefined if not installed properly
etwModule = require(etwModulePath);
}
catch (e) {
catch {
etwModule = undefined;
}

Expand Down
4 changes: 1 addition & 3 deletions src/compiler/performanceCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,4 @@ export function tryGetNativePerformanceHooks() {
*
* @internal
*/
export const timestamp = nativePerformance ? () => nativePerformance.now() :
Date.now ? Date.now :
() => +(new Date());
export const timestamp = nativePerformance ? () => nativePerformance.now() : Date.now;
Loading