Rename --fix to --save
MODIFY
packages/@romejs/core/common/bridges/WorkerBridge.ts
packages/@romejs/core/common/bridges/WorkerBridge.ts
@@ -59,9 +59,8 @@ export type WorkerAnalyzeDependencyResult = AnalyzeDependencyResult & {
export type WorkerLintOptions = {
compilerOptions?: LintCompilerOptions;
prefetchedModuleSignatures: PrefetchedModuleSignatures;
- formatOnly: boolean;
+ applyFixes: boolean;
save: boolean;
- fix: boolean;
};
export type WorkerParseOptions = {

MODIFY
packages/@romejs/core/common/fileHandlers.ts
packages/@romejs/core/common/fileHandlers.ts
@@ -332,7 +332,7 @@ function buildJSHandler(
// Run the compiler in lint-mode which is where all the rules are actually ran
const res = await compiler.lint({
- formatOnly: options.formatOnly,
+ applyFixes: options.applyFixes,
ref,
options: {
lint: options.compilerOptions,

MODIFY
packages/@romejs/core/master/commands/ci.ts
packages/@romejs/core/master/commands/ci.ts
@@ -63,7 +63,7 @@ export default createMasterCommand({
await lint.callback(req, {
formatOnly: false,
decisions: [],
- fix: flags.fix,
+ save: flags.fix,
changed: undefined,
});
});

MODIFY
packages/@romejs/core/master/commands/lint.ts
packages/@romejs/core/master/commands/lint.ts
@@ -15,7 +15,7 @@ import {commandCategories} from '@romejs/core/common/commands';
type Flags = {
decisions: Array<string>;
- fix: boolean;
+ save: boolean;
changed: undefined | string;
formatOnly: boolean;
};
@@ -32,7 +32,7 @@ export default createMasterCommand<Flags>({
decisions: consumer.get('decisions').asImplicitArray().map(
(item) => item.asString(),
),
- fix: consumer.get('fix').asBoolean(false),
+ save: consumer.get('save').asBoolean(false),
formatOnly: consumer.get('formatOnly').asBoolean(false),
changed: consumer.get('changed').asStringOrVoid(),
};
@@ -41,7 +41,8 @@ export default createMasterCommand<Flags>({
async callback(req: MasterRequest, flags: Flags): Promise<void> {
const {reporter} = req;
- if (req.query.requestFlags.review || flags.fix) {
+ // This wont trigger the shouldSave check at the bottom
+ if (req.query.requestFlags.review) {
await req.assertCleanVSC();
}
@@ -60,13 +61,6 @@ export default createMasterCommand<Flags>({
);
}
- const fixLocation = flags.fix === false
- ? undefined
- : req.getDiagnosticPointerFromFlags({
- type: 'flag',
- key: 'fix',
- });
-
// Look up arguments manually in vsc if we were passed a changes branch
let args;
if (flags.changed !== undefined) {
@@ -89,12 +83,17 @@ export default createMasterCommand<Flags>({
const opts: LinterOptions = {
hasDecisions: flags.decisions.length > 0,
compilerOptionsPerFile,
- fixLocation,
+ save: flags.save,
formatOnly: flags.formatOnly,
args,
};
const linter = new Linter(req, opts);
+
+ if (linter.shouldSave()) {
+ await req.assertCleanVSC();
+ }
+
await linter.run(req.query.requestFlags.watch);
},
});

MODIFY
packages/@romejs/core/master/linter/Linter.ts
packages/@romejs/core/master/linter/Linter.ts
import {Master, MasterRequest} from '@romejs/core';
import {LINTABLE_EXTENSIONS} from '@romejs/core/common/fileHandlers';
import {
- DiagnosticLocation,
DiagnosticSuppressions,
Diagnostics,
DiagnosticsProcessor,
@@ -36,7 +35,7 @@ type LintWatchChanges = Array<{
}>;
export type LinterOptions = {
- fixLocation: undefined | DiagnosticLocation;
+ save: boolean;
args?: Array<string>;
hasDecisions: boolean;
formatOnly: boolean;
@@ -96,7 +95,10 @@ function createDiagnosticsPrinter(
if (hasPendingFixes) {
reporter.info(
- 'Fixes available. Run <command>rome lint --review</command> to apply.',
+ 'Fixes available. Run <command>rome lint --review</command> to review.',
+ );
+ reporter.info(
+ 'Alternatively run <command>rome lint --save</command> to apply recommend fixes and formatting.',
);
}
} else {
@@ -115,33 +117,29 @@ function createDiagnosticsPrinter(
}
class LintRunner {
- constructor({
- request,
+ constructor(linter: Linter, {
graph,
- options,
events,
}: {
events: WatchEvents;
- request: MasterRequest;
graph: DependencyGraph;
- options: LinterOptions;
}) {
- this.master = request.master;
+ this.linter = linter;
+ this.master = linter.request.master;
this.graph = graph;
- this.request = request;
- this.options = options;
+ this.request = linter.request;
+ this.options = linter.options;
this.events = events;
this.compilerDiagnosticsCache = new AbsoluteFilePathMap();
this.hadDependencyValidationErrors = new AbsoluteFilePathMap();
}
hadDependencyValidationErrors: AbsoluteFilePathMap<boolean>;
-
compilerDiagnosticsCache: AbsoluteFilePathMap<{
diagnostics: Diagnostics;
suppressions: DiagnosticSuppressions;
}>;
-
+ linter: Linter;
events: WatchEvents;
master: Master;
request: MasterRequest;
@@ -155,14 +153,8 @@ class LintRunner {
let savedCount = 0;
const {master} = this.request;
- const {
- fixLocation,
- compilerOptionsPerFile,
- hasDecisions,
- formatOnly,
- } = this.options;
- const shouldFix = fixLocation !== undefined;
- const shouldSave = shouldFix || hasDecisions || formatOnly;
+ const {compilerOptionsPerFile, hasDecisions, formatOnly} = this.options;
+ const shouldSave = this.linter.shouldSave();
const queue: WorkerQueue<void> = new WorkerQueue(master);
@@ -192,8 +184,7 @@ class LintRunner {
saved,
} = await this.request.requestWorkerLint(path, {
save: shouldSave,
- formatOnly,
- fix: shouldFix,
+ applyFixes: !formatOnly,
compilerOptions,
});
processor.addSuppressions(suppressions);
@@ -385,6 +376,11 @@ export default class Linter {
request: MasterRequest;
options: LinterOptions;
+ shouldSave(): boolean {
+ const {save, hasDecisions, formatOnly} = this.options;
+ return save || hasDecisions || formatOnly;
+ }
+
getFileArgOptions(): MasterRequestGetFilesOptions {
return {
args: this.options.args,
@@ -435,10 +431,8 @@ export default class Linter {
this.request.getResolverOptionsFromFlags(),
);
- const runner = new LintRunner({
+ const runner = new LintRunner(this, {
events,
- request: this.request,
- options: this.options,
graph,
});

MODIFY
packages/@romejs/core/master/lsp/LSPServer.ts
packages/@romejs/core/master/lsp/LSPServer.ts
@@ -370,7 +370,7 @@ export default class LSPServer {
await req.init();
const linter = new Linter(req, {
- fixLocation: undefined,
+ save: false,
hasDecisions: false,
formatOnly: false,
});

MODIFY
packages/@romejs/core/worker/WorkerAPI.ts
packages/@romejs/core/worker/WorkerAPI.ts
@@ -298,11 +298,7 @@ export default class WorkerAPI {
// Relint this file without fixing it, we do this to prevent false positive error messages
return {
- ...(await this.lint(
- ref,
- {...options, formatOnly: false, fix: false},
- parseOptions,
- )),
+ ...(await this.lint(ref, {...options, save: false}, parseOptions)),
saved: true,
};
}

MODIFY
packages/@romejs/diagnostics/descriptions.ts
packages/@romejs/diagnostics/descriptions.ts
@@ -307,16 +307,11 @@ export const descriptions = createMessages(
type: 'diff',
diff: stringDiff(original, formatted),
},
- {
- type: 'log',
- category: 'info',
- message: 'Run <command>rome lint --fix</command> to apply',
- },
({
type: 'action',
hidden: true,
command: 'lint',
- instruction: 'To format this file without fixes run',
+ instruction: 'To format this file without any fixes run',
noun: 'Format file',
args: [relativeFilename],
commandFlags: {
@@ -325,13 +320,12 @@ export const descriptions = createMessages(
} as DiagnosticAdviceAction),
({
type: 'action',
- hidden: true,
command: 'lint',
- instruction: 'To format and fix this file run',
+ instruction: 'To format and apply recommended fixes run',
noun: 'Fix file',
args: [relativeFilename],
commandFlags: {
- fix: true,
+ save: true,
},
} as DiagnosticAdviceAction),
],

MODIFY
packages/@romejs/js-compiler/lint/index.ts
packages/@romejs/js-compiler/lint/index.ts
@@ -21,9 +21,9 @@ export type LintResult = {
const lintCache: Cache<LintResult> = new Cache();
export default async function lint(req: LintRequest): Promise<LintResult> {
- const {ast, sourceText, project, formatOnly, options} = req;
+ const {ast, sourceText, project, applyFixes, options} = req;
- const query = Cache.buildQuery(req);
+ const query = Cache.buildQuery(req, {applyFixes});
const cached = lintCache.get(query);
if (cached) {
return cached;
@@ -43,7 +43,7 @@ export default async function lint(req: LintRequest): Promise<LintResult> {
});
let formatAst = ast;
- if (!formatOnly) {
+ if (applyFixes) {
formatAst = formatContext.reduceRoot(ast, lintTransforms);
formatAst = addSuppressions(formatContext, formatAst);
}

MODIFY
packages/@romejs/js-compiler/lint/testHelpers.ts
packages/@romejs/js-compiler/lint/testHelpers.ts
@@ -69,7 +69,7 @@ export async function testLint(
});
const res = await lint({
- formatOnly: false,
+ applyFixes: true,
options: {},
ast,
sourceText: input,

MODIFY
packages/@romejs/js-compiler/types.ts
packages/@romejs/js-compiler/types.ts
@@ -57,7 +57,7 @@ export type TransformVisitors = Array<TransformVisitor>;
export type CompileRequest = TransformRequest & {inputSourceMap?: SourceMap};
export type LintRequest = TransformRequest & {
- formatOnly: boolean;
+ applyFixes: boolean;
};
export type TransformProjectDefinition = {

Rename --fix to --save