Skip to content

JavaScript and TypeScript

gspot checks JavaScript and TypeScript code with ESLint, with the TypeScript compiler, and with Knip, which finds code that nothing uses:

Check Stage Level What it does
javascript/eslint commit basic Runs the shipped ESLint rules on JavaScript, TypeScript, component files, and package.json.
javascript/import-cycles push basic Reports import cycles between modules.
javascript/tsc push basic Type-checks plain JavaScript through its JSDoc comments.
javascript/knip push basic Finds files, exports, and dependencies nothing uses.
javascript/biome commit all Checks the cognitive complexity of each function against limits.javascript.max_cognitive_complexity and limits.typescript.max_cognitive_complexity.
typescript/tsc push basic Runs tsc on each tsconfig project, or on the TypeScript files of a scope that has no tsconfig, with the strict options of the level.
typescript/tsconfig commit basic Requires strict in every tsconfig you write. Level all also requires noUncheckedIndexedAccess, exactOptionalPropertyTypes, noImplicitOverride, noFallthroughCasesInSwitch, noImplicitReturns, and noPropertyAccessFromIndexSignature.

javascript/eslint runs rules from ESLint, unicorn, security, import-x, regexp, n, jsdoc, and the gspot plugin, and framework configurations add their own. Level all adds sorted imports, size limits, and no default exports. gspot explain javascript/eslint <rule> explains one rule.

A package.json turns on javascript when it lists a package other than the tools that gspot runs itself, such as eslint or typescript. A dependency on vitest or wrangler counts. Declaration files alone do not turn on typescript.

ESLint gives each file one runtime: the set of global names, such as window or process, that the file can use without an import.

Files Runtime
Ordinary modules and build scripts Node.js built-ins
.cjs and .cts files, and the .js files of a package without "type": "module" Node.js built-ins and CommonJS globals
React, Vue, and Svelte application sources Browser globals
React Native sources Native globals
Next.js sources Node.js built-ins, because server components can use them

A plain script that an HTML page loads is an ordinary module. javascript/eslint reports no-undef for document in it until a record gives it the browser runtime.

To give some files another runtime, add a [[tools.eslint.override]] record, with paths from the root folder of the repository. When two records match a file, the later record wins.

gspot.toml
[[tools.eslint.override]]
paths = ["src/client/**"]
runtime = "browser"
[[tools.eslint.override]]
paths = ["src/workers/**"]
runtime = "worker"
[[tools.eslint.override]]
paths = ["src/serviceworker.js"]
runtime = "serviceworker"

Use a name from the globals package, such as browser, node, worker, or serviceworker. With an unknown name, javascript/eslint stops and lists the valid names. For server code inside a browser or React Native project, set the runtime node. Browser and native files get no Node.js lint rules.

  • With your own tsconfig.json, gspot keeps your compiler options and adds the strict options that the level needs.
  • Without one, gspot writes a TypeScript project for the source files of each scope.
  • gspot uses the TypeScript compiler of your project for the type checks and for the lint rules that read types. When your project has no compiler, gspot uses the one that gspot install pins.

javascript/tsc checks the JSDoc types of JavaScript files. It reads your jsconfig.json, or your tsconfig.json when no jsconfig.json exists. With neither file, gspot writes a jsconfig for the check.

javascript.import_extension sets how a relative import of a code file ends: js, ts, or extensionless. gspot init picks the value from the project:

Project Style
The tsconfig sets allowImportingTsExtensions or rewriteRelativeImportExtensions ts
The tsconfig uses NodeNext js
The tsconfig uses Bundler, the project depends on a bundler such as Vite, or it uses Astro, React, Svelte, or Vue extensionless
Any other project js

With Astro, React, Svelte, or Vue, ts applies only when the code already imports .ts files. An import of a style sheet or a JSON file keeps its extension. .mjs files, .cjs files, and Node.js scripts with a shebang always import the full file name, because Node.js needs it. In these files, an import alias such as #lib/log must come from the imports field of package.json, because Node.js does not read tsconfig paths.

For modules that a host application provides at run time, follow Modules that the host provides.