Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ npx hereby build # Build the native compiler into built/local/tsc
npx hereby test # Run compiler and language-service Go tests
npx hereby test:all # Also run benchmarks, tools, and API tests
npx hereby test:codegen # Run codegen tests without regenerating source outputs
npx hereby lint # Run custom golangci-lint for both Go modules
npx hereby lint # Lint both Go modules and the TypeScript package
npx hereby lint:typescript # Lint the TypeScript package using the local compiler
npx hereby generate:go # Run the generators also exposed through go generate
npx hereby generate # Regenerate all sources, assets, localization, and vendored files
npx hereby format # Format Go, TypeScript, JSON, and YAML
Expand Down
30 changes: 28 additions & 2 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1431,13 +1431,24 @@ const customLinterTool = createCachedTool({
},
});

// ESLint runs the local compiler, which can't execute when GOOS/GOARCH target another platform.
const lintTypeScriptOnHost = (!process.env.GOOS || process.env.GOOS === nodeToGOOS(process.platform))
&& (!process.env.GOARCH || process.env.GOARCH === nodeToGOARCH(process.arch, process.platform));

export const lint = task({
name: "lint",
description: "Runs golangci-lint.",
description: "Runs Go and TypeScript linters.",
dependencies: lintTypeScriptOnHost ? [local, buildAPI] : [],
run: runLint,
});

async function runLint() {
if (lintTypeScriptOnHost) {
await runLintTypeScript();
}
else {
console.log("Skipping TypeScript lint for non-host GOOS/GOARCH");
}
const lintArgs = ["run"];
if (defaultGoBuildTags.length) {
lintArgs.push("--build-tags", defaultGoBuildTags.join(","));
Expand All @@ -1451,6 +1462,21 @@ async function runLint() {
await customLinterTool.run([...lintArgs, "--config", "../.golangci.yml"], { cwd: "./tools" });
}

async function runLintTypeScript() {
const args = ["packages/typescript/{src,test,scripts}/**/*.ts"];
if (options.fix) {
args.push("--fix");
}
await run("eslint", args);
}

export const lintTypeScript = task({
name: "lint:typescript",
description: "Lints TypeScript package sources with the local compiler.",
dependencies: [local, buildAPI],
run: runLintTypeScript,
});

export const installTools = task({
name: "install-tools",
description: "Installs optional tools for developing within the repo.",
Expand Down Expand Up @@ -1513,7 +1539,7 @@ async function fixLineEndings() {
export const validate = task({
name: "validate",
description: "Generates, builds, tests, lints, and formats the repo. Pass --api to include API tests, or --all to include API and ancillary repository tests. Benchmarks are separate: test:benchmarks and test:benchmarks:api.",
dependencies: [build],
dependencies: [build, buildAPI],
run: async () => {
/** @type {{ name: string; error: unknown }[]} */
const failures = [];
Expand Down
128 changes: 128 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import eslint from "@eslint/js";
import regexpPlugin from "eslint-plugin-regexp";
import globals from "globals";
import fs from "node:fs";
import { createRequire } from "node:module";
import path from "node:path";
import tseslint from "typescript-eslint";

const require = createRequire(import.meta.url);
const rulesDir = path.join(import.meta.dirname, "packages/typescript/eslint/rules");
const rules = Object.fromEntries(
fs.readdirSync(rulesDir)
.filter(file => file.endsWith(".cjs") && file !== "utils.cjs")
.map(file => [file.slice(0, -4), require(path.join(rulesDir, file))]),
);

export default tseslint.config(
{
ignores: [
"**/node_modules/**",
"packages/typescript/dist/**",
"packages/typescript/vendor/**",
"packages/typescript/**/*.generated.ts",
"packages/typescript/src/api/sync/api.ts",
"packages/typescript/src/api/sync/types.ts",
"packages/typescript/test/sync/api.bench.ts",
"packages/typescript/test/sync/api.test.ts",
"packages/typescript/test/sync/astnav.test.ts",
"packages/typescript/test/generators/api.bench.ts",
],
},
{
files: ["packages/typescript/{src,test,scripts}/**/*.ts"],
extends: [
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.stylistic,
regexpPlugin.configs["flat/recommended"],
],
plugins: { local: { rules } },
languageOptions: {
globals: globals.node,
parserOptions: {
projectService: { EXPERIMENTAL_backend: "tsgo" },
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
"dot-notation": "off",
"eqeqeq": "off", // Enforced below with an exception for nullish comparisons.
"no-caller": "error",
"no-constant-condition": ["error", { checkLoops: false }],
"no-eval": "error",
"no-extra-bind": "error",
"no-new-func": "error",
"no-new-wrappers": "error",
"no-return-await": "error",
"no-template-curly-in-string": "error",
"no-throw-literal": "error",
"no-undef-init": "error",
"no-var": "error",
"object-shorthand": "error",
"prefer-const": "error",
"prefer-object-spread": "error",
"unicode-bom": ["error", "never"],
"no-restricted-syntax": [
"error",
{ selector: "Literal[raw=null]", message: "Avoid using null; use undefined instead." },
{ selector: "TSNullKeyword", message: "Avoid using null; use undefined instead." },
{
selector: "BinaryExpression[operator=/^(==|!=)$/]:not([left.type='Identifier'][left.name='undefined']):not([right.type='Identifier'][right.name='undefined'])",
message: "Expected strict equality unless comparing with undefined.",
},
],
"no-extra-boolean-cast": "off",
"no-case-declarations": "off",
"no-cond-assign": "off",
"no-control-regex": "off",
"no-inner-declarations": "off",
"@typescript-eslint/naming-convention": [
"error",
{ selector: "typeLike", format: ["PascalCase"], leadingUnderscore: "allow", filter: { regex: "^(__String|[A-Za-z]+_[A-Za-z]+)$", match: false } },
{ selector: "interface", format: ["PascalCase"], custom: { regex: "^I[A-Z]", match: false }, filter: { regex: "^I(Arguments|TextWriter|O([A-Z][a-z]+[A-Za-z]*)?)$", match: false } },
{ selector: "variable", format: ["camelCase", "PascalCase", "UPPER_CASE"], leadingUnderscore: "allow", filter: { regex: "^(_{1,2}filename|_{1,2}dirname|_+|[A-Za-z]+_[A-Za-z]+)$", match: false } },
{ selector: "function", format: ["camelCase", "PascalCase"], leadingUnderscore: "allow", filter: { regex: "^[A-Za-z]+_[A-Za-z]+$", match: false } },
{ selector: "parameter", format: ["camelCase"], leadingUnderscore: "allow", filter: { regex: "^(_+|[A-Za-z]+_[A-Z][a-z]+)$", match: false } },
{ selector: "method", format: ["camelCase", "PascalCase"], leadingUnderscore: "allow", filter: { regex: "^([0-9]+|[A-Za-z]+(?:_[A-Za-z]+)+)$", match: false } },
{ selector: "memberLike", format: ["camelCase"], leadingUnderscore: "allow", filter: { regex: "^([0-9]+|[A-Za-z]+(?:_[A-Za-z]+)+)$", match: false } },
{ selector: "enumMember", format: ["camelCase", "PascalCase"], leadingUnderscore: "allow", filter: { regex: "^[A-Za-z]+_[A-Za-z]+$", match: false } },
{ selector: "property", format: null },
],
"@typescript-eslint/unified-signatures": "error",
"@typescript-eslint/dot-notation": ["error", {
allowIndexSignaturePropertyAccess: true,
allowPrivateClassPropertyAccess: true,
allowProtectedClassPropertyAccess: true,
}],
"no-unused-expressions": "off",
"@typescript-eslint/no-unused-expressions": ["error", { allowTernary: true }],
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/class-literal-property-style": "off",
"@typescript-eslint/consistent-indexed-object-style": "off",
"@typescript-eslint/consistent-generic-constructors": "off",
"@typescript-eslint/no-duplicate-enum-values": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-non-null-asserted-optional-chain": "off",
"@typescript-eslint/no-empty-object-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-require-imports": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ argsIgnorePattern: "^(_+$|_[^_])", varsIgnorePattern: "^(_+$|_[^_])" },
],
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/prefer-optional-chain": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"local/only-arrow-functions": ["error", { allowNamedFunctions: true, allowDeclarations: true }],
"local/argument-trivia": "error",
"local/no-in-operator": "error",
"local/debug-assert": "error",
"local/no-keywords": "error",
"local/jsdoc-format": "error",
"local/js-extensions": "error",
"local/no-array-mutating-method-expressions": "error",
},
},
);
Loading
Loading