Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
id: prefer-node-process
valid:
- |
import process from "node:process";
const ci = process.env.CI === "true";
- |
import process from "node:process";
import { join } from "node:path";
process.exitCode = 1;
console.log(join(process.cwd(), "dist"));
- |
import { env } from "node:process";
const home = env.HOME;
- |
const process = spawn("node", ["dist/index.js"]);
process.stdout.on("data", () => {});
- |
export const process = spawn("node", ["dist/index.js"]);
process.stdout.on("data", () => {});
- |
function kill(process: ChildProcess) {
process.kill();
}
- |
const run = (process?: ChildProcess) => process?.pid;
- |
const pid = (process) => process.pid;
- |
class Runner {
stop(process: ChildProcess) {
return process.kill();
}
}
- |
try {
run();
} catch (process) {
console.error(process);
}
- |
function main() {
const process = spawn("git", ["status"]);
if (process.pid) {
process.stdout.on("data", () => {});
}
}
- |
function outer() {
const process = spawn("git", ["status"]);
const inner = () => process.pid;
return inner();
}
- |
const settings = { process: "batch" };
const mode = settings.process;
- |
import { execFile } from "node:child_process";
execFile("git", ["status"]);
invalid:
- |
const ci = process.env.CI === "true";
- |
import { join } from "node:path";
console.log(join(process.cwd(), "dist"));
- |
process.exitCode = 1;
- |
export function isTTY(): boolean {
return process.stdout.isTTY === true;
}
- |
import type { Process } from "./types";
const { env } = process;
- |
function kill(process: ChildProcess) {
process.kill();
}
function cwd() {
return process.cwd();
}
- |
function main() {
{
const process = spawn("git", ["status"]);
process.stdout.on("data", () => {});
}
return process.cwd();
}
- |
try {
run();
} catch (process) {
console.error(process);
}
process.exitCode = 1;
- |
const nodeProcess = globalThis.process;
- |
import process from "node:process";
const home = globalThis.process.env.HOME;
- |
function main(process: ChildProcess) {
return globalThis.process.cwd();
}
113 changes: 113 additions & 0 deletions .taskless/rules/sg/prefer-node-process/prefer-node-process.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
id: prefer-node-process
language: TypeScript
severity: error
message: Import process from "node:process" instead of reaching for the global.
note: |
An explicit `import process from "node:process";` makes the Node
dependency visible in the module graph: a build-time check that reads
rollup's resolved imports can see an import, but not a reach for a
global. It is also the convention every other Node built-in here
already follows (`node:path`, `node:fs`, `node:child_process`).

Reference behaviour: ESLint `n/prefer-global/process: ["error", "never"]`.

There is no auto-fix. An import needs placement (Node built-ins first,
grouped, per .conventions/STYLEGUIDE-CODE.md), so the finding names the
file and you add the line by hand.

Two forms are reported:

- A bare `process` identifier in a file with no `import … from
"node:process"`, unless an ANCESTOR of the reference binds the name:
an enclosing function, arrow, or method with a parameter named
`process`, an enclosing `catch (process)`, or an enclosing block (or
the file itself) holding a `const`/`let`/`var` declarator named
`process`. A binding in a sibling scope does not count, so a shadow
in one function does not silence a global reach in another.
- `globalThis.process`, always. It is the same reach with the global
spelled out, and no import or shadow makes it the module-graph
dependency this rule asks for. Import and use `process` instead.
files:
- "packages/cli/src/**/*.ts"
rule:
any:
- pattern: globalThis.process
- kind: identifier
regex: '^process$'
all:
- not:
inside:
stopBy: end
kind: import_statement
- inside:
stopBy: end
kind: program
not:
has:
kind: import_statement
has:
stopBy: end
kind: string_fragment
regex: '^node:process$'
- not:
inside:
stopBy: end
any:
# an enclosing function whose parameter list binds `process`
- any:
- kind: function_declaration
- kind: function_expression
- kind: generator_function_declaration
- kind: generator_function
- kind: arrow_function
- kind: method_definition
has:
field: parameters
has:
any:
- kind: required_parameter
- kind: optional_parameter
has:
field: pattern
kind: identifier
regex: '^process$'
# `process => …`: a single unparenthesised arrow parameter
- kind: arrow_function
has:
field: parameter
kind: identifier
regex: '^process$'
# an enclosing `catch (process)`
- kind: catch_clause
has:
field: parameter
kind: identifier
regex: '^process$'
# an enclosing block, or the file, declaring `process` as a
# direct child: a `const`/`let`/`var`, or an `export` of one
- any:
- kind: statement_block
- kind: program
has:
any:
- any:
- kind: lexical_declaration
- kind: variable_declaration
has:
kind: variable_declarator
has:
field: name
kind: identifier
regex: '^process$'
- kind: export_statement
has:
field: declaration
any:
- kind: lexical_declaration
- kind: variable_declaration
has:
kind: variable_declarator
has:
field: name
kind: identifier
regex: '^process$'
1 change: 1 addition & 0 deletions packages/cli/src/api/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readFileSync } from "node:fs";
import { join } from "node:path";
import process from "node:process";

import { getConfigDirectory } from "../auth/token";

Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/auth/login-interactive.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import process from "node:process";

import { deviceFlowProvider } from "./device-flow";
import { getToken, saveToken } from "./token";
import { resolveRepositoryUrl } from "../util/git-remote";
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/auth/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { existsSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
import process from "node:process";

import { addToGitignore } from "../filesystem/gitignore";
import { getCliPrefix } from "../util/package-manager";
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/agent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { resolve } from "node:path";
import process from "node:process";

import {
defineCommand,
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { resolve } from "node:path";
import process from "node:process";
import { defineCommand } from "citty";

import { loginInteractive } from "../auth/login-interactive";
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/check.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { resolve, isAbsolute, relative } from "node:path";
import { stat } from "node:fs/promises";
import process from "node:process";
import { defineCommand } from "citty";

import { hasValeRules, runEngines } from "../rules/dispatch";
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/demo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { stat } from "node:fs/promises";
import { resolve } from "node:path";
import process from "node:process";

import { defineCommand } from "citty";

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/detect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { resolve } from "node:path";
import process from "node:process";

import { defineCommand } from "citty";

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/feedback.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readFile } from "node:fs/promises";
import { resolve } from "node:path";
import process from "node:process";

import { defineCommand } from "citty";
import { ZodError } from "zod";
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/info.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { join, resolve } from "node:path";
import process from "node:process";
import { defineCommand } from "citty";

import { checkStaleness } from "../install/install";
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { join, resolve } from "node:path";
import process from "node:process";
import { defineCommand } from "citty";

import { ensureTasklessDirectory } from "../filesystem/directory";
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/onboard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { resolve } from "node:path";
import process from "node:process";

import { defineCommand } from "citty";

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/rules.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { resolve } from "node:path";
import { readFile } from "node:fs/promises";
import process from "node:process";
import { defineCommand } from "citty";

import { ZodError } from "zod";
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/verify.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { resolve } from "node:path";
import process from "node:process";

import { defineCommand } from "citty";

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/filesystem/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import process from "node:process";

import { CLIError } from "../util/cli-error";
import { buildInvocation } from "../util/invocation";
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import process from "node:process";

import { defineCommand, runCommand, showUsage } from "citty";

import { createAgentCommand } from "./commands/agent";
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/rules/platform-binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { spawnSync } from "node:child_process";
import { existsSync } from "node:fs";
import { createRequire } from "node:module";
import { dirname, resolve } from "node:path";
import process from "node:process";
import { fileURLToPath } from "node:url";

/**
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/rules/runtime/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { readFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
import process from "node:process";

import type { Finding, Match } from "../../types/runtime-rule";

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/rules/runtime/narrow.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { spawn } from "node:child_process";
import { copyFile, mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import process from "node:process";
import { createInterface } from "node:readline";
import { join } from "node:path";
import { StringDecoder } from "node:string_decoder";
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/rules/scan.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { spawn } from "node:child_process";
import { dirname, resolve } from "node:path";
import process from "node:process";
import { createInterface } from "node:readline";
import { StringDecoder } from "node:string_decoder";
import { fileURLToPath } from "node:url";
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/rules/vale/run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { spawn } from "node:child_process";
import { stat } from "node:fs/promises";
import { isAbsolute, join, resolve as resolvePath } from "node:path";
import process from "node:process";
import { StringDecoder } from "node:string_decoder";

import type { CheckResult } from "../../types/check";
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/rules/verify.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readFile, readdir } from "node:fs/promises";
import { join } from "node:path";
import { spawn } from "node:child_process";
import process from "node:process";
import { StringDecoder } from "node:string_decoder";
import { stripVTControlCharacters } from "node:util";

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/telemetry-run.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { resolve } from "node:path";
import process from "node:process";

import type { TelemetryClient } from "./telemetry";
import { splitRawArguments } from "./util/argv";
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/telemetry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { randomUUID } from "node:crypto";
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import process from "node:process";

import { PostHog } from "posthog-node";
import { decodeJwt } from "jose";
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/util/adoption-dimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { execFile } from "node:child_process";
import { createHash } from "node:crypto";
import { existsSync } from "node:fs";
import { resolve } from "node:path";
import process from "node:process";

import { LANGUAGE_MARKERS } from "../detect/scan";
import { resolveRepositoryPath } from "./git-remote";
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/util/color.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import process from "node:process";

import chalk from "chalk";

/**
Expand Down
Loading
Loading