Remove format project config option, remove enabled config categories
MODIFY
package.json
package.json
"bundler": {
"mode": "modern"
},
- "tests": {
- "enabled": true
- },
- "format": {
- "enabled": true
- },
"lint": {
- "enabled": true,
"ignore": [
"build",
"coverage",

MODIFY
packages/@romejs/core/client/commands/init.ts
packages/@romejs/core/client/commands/init.ts
@@ -64,31 +64,6 @@ export default createLocalCommand(
config.version = `^${VERSION}`;
- const enabledComponents = await reporter.select('Features enabled', {
- yes: flags.defaults,
- options: {
- lint: {
- label: 'Lint',
- },
- format: {
- label: 'Format',
- },
- tests: {
- label: 'Testing',
- },
- },
- defaults: ['lint'],
- });
- if (enabledComponents.has('lint')) {
- config.lint = {enabled: true};
- }
- if (enabledComponents.has('format')) {
- config.format = {enabled: true};
- }
- if (enabledComponents.has('tests')) {
- config.tests = {enabled: true};
- }
-
await writeFile(configPath, `${JSON.stringify(config, null, ' ')}\n`);
reporter.success(

MODIFY
packages/@romejs/core/common/fileHandlers.ts
packages/@romejs/core/common/fileHandlers.ts
@@ -78,7 +78,6 @@ export function getFileHandlerAssert(
export type ExtensionLintInfo = ExtensionHandlerMethodInfo & {
options: WorkerLintOptions;
- format: boolean;
};
export type ExtensionLintResult = {
@@ -174,7 +173,7 @@ const jsonHandler: ExtensionHandler = {
hasteMode: 'noext',
async format(info: ExtensionHandlerMethodInfo): Promise<ExtensionLintResult> {
- const {file, project, worker} = info;
+ const {file, worker} = info;
const {uid} = file;
const real = createAbsoluteFilePath(file.real);
@@ -183,7 +182,6 @@ const jsonHandler: ExtensionHandler = {
let formatted: string = sourceText;
- if (project.config.format.enabled) {
if (sourceText.length > 50_000) {
// Fast path for big JSON files
parseJSON({
@@ -199,12 +197,8 @@ const jsonHandler: ExtensionHandler = {
if (hasExtensions) {
formatted = stringifyJSON({consumer, comments});
} else {
- formatted = String(JSON.stringify(
- consumer.asUnknown(),
- undefined,
- ' ',
- ));
- }
+ formatted =
+ String(JSON.stringify(consumer.asUnknown(), undefined, ' '));
}
}
@@ -326,7 +320,7 @@ function buildJSHandler(
},
async lint(info: ExtensionLintInfo): Promise<ExtensionLintResult> {
- const {file: ref, project, format, parseOptions, options, worker} = info;
+ const {file: ref, project, parseOptions, options, worker} = info;
const {ast, sourceText, generated}: ParseResult = await worker.parseJS(
ref,
@@ -343,7 +337,6 @@ function buildJSHandler(
ast,
project,
sourceText,
- format,
});
// Extract lint diagnostics

MODIFY
packages/@romejs/core/master/MasterRequest.ts
packages/@romejs/core/master/MasterRequest.ts
@@ -27,7 +27,7 @@ import {
DiagnosticsPrinterFlags,
} from '@romejs/cli-diagnostics';
import {
- ProjectConfigCategoriesWithIgnoreAndEnabled,
+ ProjectConfigCategoriesWithIgnore,
ProjectDefinition,
} from '@romejs/project';
import {ResolverOptions} from './fs/Resolver';
@@ -100,14 +100,15 @@ type ResolvedArg = {
type ResolvedArgs = Array<ResolvedArg>;
-export type MasterRequestGetFilesOptions = Omit<MemoryFSGlobOptions,
- | 'getProjectIgnore'
- | 'getProjectEnabled'> & {
+export type MasterRequestGetFilesOptions = Omit<
+ MemoryFSGlobOptions,
+ 'getProjectIgnore'
+> & {
ignoreArgumentMisses?: boolean;
ignoreProjectIgnore?: boolean;
disabledDiagnosticCategory?: DiagnosticCategory;
advice?: DiagnosticAdvice;
- configCategory?: ProjectConfigCategoriesWithIgnoreAndEnabled;
+ configCategory?: ProjectConfigCategoriesWithIgnore;
verb?: string;
noun?: string;
args?: Array<string>;
@@ -597,9 +598,6 @@ export default class MasterRequest {
const extendedGlobOpts: MemoryFSGlobOptions = {...opts};
if (configCategory !== undefined) {
- extendedGlobOpts.getProjectEnabled =
- (project) => project.config[configCategory].enabled;
-
extendedGlobOpts.getProjectIgnore = (project) => ignoreProjectIgnore
? []
: project.config[configCategory].ignore;
@@ -634,54 +632,6 @@ export default class MasterRequest {
? []
: [...opts.advice];
- // Hint if `path` failed `globOpts.test`
- if (configCategory !== undefined &&
- !project.config[configCategory].enabled) {
- const enabledSource = master.projectManager.findProjectConfigConsumer(
- project,
- (consumer) => consumer.has(configCategory) && consumer.get(
- configCategory,
- ).get('enabled'),
- );
-
- const explanationPrefix = opts.verb === undefined
- ? 'Files excluded'
- : `Files excluded from ${opts.verb}`;
-
- if (opts.disabledDiagnosticCategory !== undefined) {
- category = opts.disabledDiagnosticCategory;
- }
-
- if (enabledSource.value === undefined) {
- let explanation = `${explanationPrefix} as it's not enabled for this project`;
- if (configCategory !== undefined) {
- explanation +=
- `. Run <command>rome config enable-category ${configCategory}</command> to enable it.`;
- }
- advice.push({
- type: 'log',
- category: 'info',
- message: explanation,
- });
- } else {
- advice.push(
- {
- type: 'log',
- category: 'info',
- message: `${explanationPrefix} as it's explicitly disabled in this project config`,
- },
- );
-
- const disabledPointer = enabledSource.value.getDiagnosticLocation(
- 'value',
- );
- advice.push({
- type: 'frame',
- location: disabledPointer,
- });
- }
- }
-
// Hint if all files were ignored
if (configCategory !== undefined && !ignoreProjectIgnore) {
const {paths: withoutIgnore} = await this.getFilesFromArgs({

MODIFY
packages/@romejs/core/master/fs/MemoryFileSystem.ts
packages/@romejs/core/master/fs/MemoryFileSystem.ts
@@ -139,7 +139,6 @@ export type MemoryFSGlobOptions = {
extensions?: Array<string>;
overrideIgnore?: PathPatterns;
getProjectIgnore?: (project: ProjectDefinition) => PathPatterns;
- getProjectEnabled?: (project: ProjectDefinition) => boolean;
test?: (path: AbsoluteFilePath) => boolean;
};
@@ -921,13 +920,7 @@ export default class MemoryFileSystem {
cwd: AbsoluteFilePath,
opts: MemoryFSGlobOptions = {},
): AbsoluteFilePathSet {
- const {
- extensions,
- getProjectIgnore,
- getProjectEnabled,
- test,
- overrideIgnore = [],
- } = opts;
+ const {extensions, getProjectIgnore, test, overrideIgnore = []} = opts;
const paths: AbsoluteFilePathSet = new AbsoluteFilePathSet();
@@ -965,10 +958,6 @@ export default class MemoryFileSystem {
// Add if a matching file
if (this.files.has(path) && ignoreMatched === 'NO_MATCH') {
- if (getProjectEnabled !== undefined && !getProjectEnabled(project)) {
- continue;
- }
-
if (test !== undefined && !test(path)) {
continue;
}

MODIFY
packages/@romejs/core/master/linter/Linter.ts
packages/@romejs/core/master/linter/Linter.ts
@@ -12,7 +12,6 @@ import {
DiagnosticSuppressions,
Diagnostics,
DiagnosticsProcessor,
- descriptions,
} from '@romejs/diagnostics';
import {FileReference} from '@romejs/core/common/types/files';
import {EventSubscription} from '@romejs/events';
@@ -427,8 +426,6 @@ export default class Linter {
this.request.getResolverOptionsFromFlags(),
);
- const {fixLocation} = this.options;
-
const runner = new LintRunner({
events,
request: this.request,
@@ -439,22 +436,11 @@ export default class Linter {
let firstRun = true;
return this.request.watchFilesFromArgs(this.getFileArgOptions(), async (
- {paths: evictedPaths, projects},
+ {paths: evictedPaths},
initial,
) => {
const processor = this.createDiagnosticsProcessor(evictedPaths, runner);
- if (fixLocation !== undefined) {
- for (const project of projects) {
- if (!project.config.format.enabled) {
- processor.addDiagnostic({
- location: fixLocation,
- description: descriptions.FORMAT.DISABLED,
- });
- }
- }
- }
-
const result = await runner.run({firstRun, evictedPaths, processor});
events.onChanges(result, initial, runner);
firstRun = false;

MODIFY
packages/@romejs/core/worker/WorkerAPI.ts
packages/@romejs/core/worker/WorkerAPI.ts
@@ -31,7 +31,6 @@ import {
AnalyzeDependencyResult,
UNKNOWN_ANALYZE_DEPENDENCIES_RESULT,
} from '../common/types/analyzeDependencies';
-import {matchPathPatterns} from '@romejs/path-match';
// Some Windows git repos will automatically convert Unix line endings to Windows
// This retains the line endings for the formatted code if they were present in the source
@@ -197,17 +196,6 @@ export default class WorkerAPI {
}
}
- shouldFormat(ref: FileReference): boolean {
- const project = this.worker.getProject(ref.project);
-
- return project.config.format.enabled && matchPathPatterns(
- ref.real,
- project.config.lint.ignore,
- ) === 'NO_MATCH' &&
- matchPathPatterns(ref.real, project.config.format.ignore) ===
- 'NO_MATCH';
- }
-
async _format(
ref: FileReference,
parseOptions: WorkerParseOptions,
@@ -215,10 +203,6 @@ export default class WorkerAPI {
const project = this.worker.getProject(ref.project);
this.logger.info(`Formatting:`, ref.real);
- if (!this.shouldFormat(ref)) {
- return;
- }
-
const {handler} = getFileHandlerAssert(ref.real, project.config);
const {format} = handler;
if (format === undefined) {
@@ -261,7 +245,6 @@ export default class WorkerAPI {
return this._format(ref, parseOptions);
} else {
return lint({
- format: this.shouldFormat(ref),
file: ref,
project,
worker: this.worker,

MODIFY
packages/@romejs/js-compiler/api/lint.test.ts
packages/@romejs/js-compiler/api/lint.test.ts
@@ -19,7 +19,6 @@ import {printDiagnosticsToString} from '@romejs/cli-diagnostics';
type TestLintOptions = {
category: undefined | DiagnosticCategory;
- format?: boolean;
sourceType?: ConstSourceType;
syntax?: Array<ConstProgramSyntax>;
};
@@ -34,12 +33,11 @@ export async function testLintMultiple(
}
}
-export async function testLint(t: TestHelper, input: string, {
- syntax = [],
- category,
- format = false,
- sourceType = 'module',
-}: TestLintOptions) {
+export async function testLint(
+ t: TestHelper,
+ input: string,
+ {syntax = [], category, sourceType = 'module'}: TestLintOptions,
+) {
t.addToAdvice({
type: 'log',
category: 'info',
@@ -51,7 +49,6 @@ export async function testLint(t: TestHelper, input: string, {
data: {
category,
syntax,
- format,
sourceType,
},
});
@@ -76,7 +73,6 @@ export async function testLint(t: TestHelper, input: string, {
const res = await lint({
options: {},
- format,
ast,
sourceText: input,
project: {
@@ -102,9 +98,7 @@ export async function testLint(t: TestHelper, input: string, {
suppressions: res.suppressions,
}));
- if (format) {
await t.snapshotNamed(`${snapshotName}: formatted`, res.src);
- }
t.clearAdvice();
}
@@ -113,7 +107,7 @@ test('format disabled in project config should not regenerate the file', async (
t,
) => {
// Intentionally weird formatting
- await testLint(t, 'foobar ( "yes" );', {category: undefined, format: false});
+ await testLint(t, 'foobar ( "yes" );', {category: undefined});
});
test(
@@ -121,7 +115,6 @@ test(
async (t) => {
await testLint(t, 'foobar ( "yes" );', {
category: undefined,
- format: true,
});
},
);

MODIFY
packages/@romejs/js-compiler/api/lint.ts
packages/@romejs/js-compiler/api/lint.ts
@@ -45,8 +45,6 @@ export type LintResult = {
const lintCache: Cache<LintResult> = new Cache();
-export type FormatRequest = TransformRequest & {format: boolean};
-
function getStartLine(node: AnyNode): undefined | Number1 {
const {loc} = node;
if (loc === undefined) {
@@ -159,8 +157,8 @@ function addSuppressions(context: CompilerContext, ast: Program): Program {
});
}
-export default async function lint(req: FormatRequest): Promise<LintResult> {
- const {ast, sourceText, project, options, format} = req;
+export default async function lint(req: TransformRequest): Promise<LintResult> {
+ const {ast, sourceText, project, options} = req;
const query = Cache.buildQuery(req);
const cached = lintCache.get(query);
@@ -168,11 +166,8 @@ export default async function lint(req: FormatRequest): Promise<LintResult> {
return cached;
}
- let formattedMappings: undefined | Mappings;
- let formattedCode = sourceText;
- if (format) {
// Perform autofixes
- const context = new CompilerContext({
+ const formatContext = new CompilerContext({
options,
ast,
project,
@@ -182,20 +177,19 @@ export default async function lint(req: FormatRequest): Promise<LintResult> {
},
});
- let newAst = context.reduceRoot(ast, lintTransforms);
- newAst = addSuppressions(context, newAst);
+ let formattedAst = formatContext.reduceRoot(ast, lintTransforms);
+ formattedAst = addSuppressions(formatContext, formattedAst);
- const generator = formatJS(newAst, {
+ const generator = formatJS(formattedAst, {
typeAnnotations: true,
sourceMaps: true,
format: 'pretty',
sourceText,
});
- formattedCode = generator.getCode();
- formattedMappings = generator.getMappings();
- }
+ const formattedCode = generator.getCode();
+ const formattedMappings = generator.getMappings();
- // Run lints (could be with the autofixed AST)
+ // Run lints
const context = new CompilerContext({
ast,
project,

MODIFY
packages/@romejs/js-formatter/builders/patterns/AssignmentAssignmentPattern.ts
packages/@romejs/js-formatter/builders/patterns/AssignmentAssignmentPattern.ts
@@ -12,12 +12,12 @@ import {
AssignmentAssignmentPattern,
assignmentAssignmentPattern,
} from '@romejs/js-ast';
+import BindingAssignmentPattern from './BindingAssignmentPattern';
export default function AssignmentAssignmentPattern(
builder: Builder,
node: AnyNode,
): Tokens {
node = assignmentAssignmentPattern.assert(node);
-
- throw new Error('unimplemented');
+ return BindingAssignmentPattern(builder, node);
}

MODIFY
packages/@romejs/js-formatter/builders/patterns/BindingAssignmentPattern.ts
packages/@romejs/js-formatter/builders/patterns/BindingAssignmentPattern.ts
@@ -17,7 +17,9 @@ export default function BindingAssignmentPattern(
builder: Builder,
node: AnyNode,
): Tokens {
- node = bindingAssignmentPattern.assert(node);
+ node = node.type === 'AssignmentAssignmentPattern'
+ ? node
+ : bindingAssignmentPattern.assert(node);
return [
concat(builder.tokenize(node.left, node)),

MODIFY
packages/@romejs/project/load.ts
packages/@romejs/project/load.ts
@@ -193,7 +193,6 @@ export function normalizeProjectConfig(
resolver: {},
develop: {},
typeCheck: {},
- format: {},
tests: {},
files: {},
vcs: {},
@@ -293,10 +292,6 @@ export function normalizeProjectConfig(
const lint = consumer.get('lint');
if (categoryExists(lint)) {
- if (lint.has('enabled')) {
- config.lint.enabled = lint.get('enabled').asBoolean();
- }
-
if (lint.has('ignore')) {
config.lint.ignore = arrayOfPatterns(lint.get('ignore'));
}
@@ -306,23 +301,8 @@ export function normalizeProjectConfig(
}
}
- const format = consumer.get('format');
- if (categoryExists(format)) {
- if (format.has('enabled')) {
- config.format.enabled = format.get('enabled').asBoolean();
- }
-
- if (format.has('ignore')) {
- config.format.ignore = arrayOfPatterns(format.get('ignore'));
- }
- }
-
const tests = consumer.get('tests');
if (categoryExists(tests)) {
- if (tests.has('enabled')) {
- config.tests.enabled = tests.get('enabled').asBoolean();
- }
-
if (tests.has('ignore')) {
config.tests.ignore = arrayOfPatterns(tests.get('ignore'));
}
@@ -556,10 +536,6 @@ function mergePartialConfig<
...a.tests,
...b.tests,
},
- format: {
- ...a.format,
- ...b.format,
- },
files: {
...a.files,
...b.files,

MODIFY
packages/@romejs/project/types.ts
packages/@romejs/project/types.ts
@@ -42,7 +42,6 @@ export type ProjectConfigObjects = {
ignore: PathPatterns;
};
lint: {
- enabled: boolean;
globals: Array<string>;
ignore: PathPatterns;
};
@@ -50,12 +49,7 @@ export type ProjectConfigObjects = {
enabled: boolean;
libs: AbsoluteFilePathSet;
};
- format: {
- enabled: boolean;
- ignore: PathPatterns;
- };
tests: {
- enabled: boolean;
ignore: PathPatterns;
};
develop: {serveStatic: boolean};
@@ -70,10 +64,7 @@ export type ProjectConfigObjects = {
targets: Map<string, ProjectConfigTarget>;
};
-export type ProjectConfigCategoriesWithIgnoreAndEnabled =
- | 'tests'
- | 'format'
- | 'lint';
+export type ProjectConfigCategoriesWithIgnore = 'tests' | 'lint';
export type ProjectConfigTarget = {constraints: Array<string>};
@@ -183,24 +174,17 @@ export const DEFAULT_PROJECT_CONFIG: ProjectConfig = {
enabled: false,
},
- format: {
- enabled: false,
- ignore: [],
- },
-
haste: {
enabled: false,
ignore: [],
},
lint: {
- enabled: false,
ignore: [],
globals: [],
},
tests: {
- enabled: false,
ignore: [],
},

Remove format project config option, remove enabled config categories