Better complaints when features disabled and we're fetching files from args
MODIFY
packages/@romejs/core/master/MasterRequest.ts
packages/@romejs/core/master/MasterRequest.ts
@@ -17,6 +17,7 @@ import {
PartialDiagnosticAdvice,
createSingleDiagnosticError,
DiagnosticsError,
+ DiagnosticCategory,
} from '@romejs/diagnostics';
import {DiagnosticsPrinterFlags} from '@romejs/cli-diagnostics';
import {ProjectDefinition} from '@romejs/project';
@@ -278,14 +279,19 @@ export default class MasterRequest {
globOpts:
& MemoryFSGlobOptions
& {
+ disabledDiagnosticCategory?: DiagnosticCategory,
advice?: PartialDiagnosticAdvice;
configCategory?: string;
verb?: string;
noun?: string;
} = {},
- ): Promise<AbsoluteFilePathSet> {
+ ): Promise<{
+ projects: Set<ProjectDefinition>;
+ paths: AbsoluteFilePathSet,
+ }> {
const {master} = this;
const {flags} = this.client;
+ const projects: Set<ProjectDefinition> = new Set();
// Build up args, defaulting to the current project dir if none passed
const rawArgs = [...this.query.args];
@@ -302,6 +308,7 @@ export default class MasterRequest {
pointer,
project,
});
+ projects.add(project);
} else {
for (let i = 0;
i < rawArgs.length;
@@ -321,10 +328,13 @@ export default class MasterRequest {
pointer,
});
- resolvedArgs.push({
- project: this.master.projectManager.assertProjectExisting(
+ const project = this.master.projectManager.assertProjectExisting(
resolved.path,
- ),
+ );
+ projects.add(project);
+
+ resolvedArgs.push({
+ project,
path: resolved.path,
pointer,
});
@@ -343,6 +353,8 @@ export default class MasterRequest {
continue;
}
+ let category: DiagnosticCategory = 'args/fileNotFound';
+
let advice: PartialDiagnosticAdvice = globOpts.advice === undefined
? [] : [...globOpts.advice];
@@ -356,6 +368,10 @@ export default class MasterRequest {
const explanationPrefix = globOpts.verb === undefined
? 'Files excluded' : `Files excluded from ${globOpts.verb}`;
+ if (globOpts.disabledDiagnosticCategory !== undefined) {
+ category = globOpts.disabledDiagnosticCategory;
+ }
+
if (testSource.value === undefined) {
let explanation =
`${explanationPrefix} as it's not enabled for this project`;
@@ -392,7 +408,7 @@ export default class MasterRequest {
if (globOpts.getProjectIgnore !== undefined) {
const ignore = globOpts.getProjectIgnore(project);
- const withoutIgnore = await this.getFilesFromArgs({
+ const {paths: withoutIgnore} = await this.getFilesFromArgs({
...globOpts,
getProjectIgnore: undefined,
});
@@ -435,14 +451,14 @@ export default class MasterRequest {
throw createSingleDiagnosticError({
...pointer,
- category: 'args/fileNotFound',
+ category,
message: globOpts.noun === undefined
? 'No files found' : `No files to ${globOpts.noun} found`,
advice,
});
}
- return paths;
+ return {paths, projects};
}
normalizeCompileResult(res: WorkerCompileResult): WorkerCompileResult {

MODIFY
packages/@romejs/core/master/commands/format.ts
packages/@romejs/core/master/commands/format.ts
@@ -29,7 +29,7 @@ export default createMasterCommand({
async default(req: MasterRequest, flags: Flags): Promise<void> {
const {reporter, master} = req;
- const paths: AbsoluteFilePathSet = await req.getFilesFromArgs({
+ const {paths} = await req.getFilesFromArgs({
getProjectIgnore: (project) =>
({
patterns: project.config.format.ignore,
@@ -54,6 +54,7 @@ export default createMasterCommand({
verb: 'linting',
configCategory: 'format',
extensions: FORMATTABLE_EXTENSIONS,
+ disabledDiagnosticCategory: 'format/disabled',
});
if (paths.size === 0) {

MODIFY
packages/@romejs/core/master/commands/lint.ts
packages/@romejs/core/master/commands/lint.ts
@@ -10,6 +10,7 @@ import {createMasterCommand} from '../../commands';
import Linter from '../linter/Linter';
import {commandCategories} from '../../commands';
import {Consumer} from '@romejs/consume';
+import { DiagnosticPointer } from '@romejs/diagnostics';
type Flags = {fix: boolean};
@@ -94,7 +95,7 @@ function initWatchLint(req: MasterRequest, reject: (err: Error) => void) {
runWatchLint();
}
-async function runLint(req: MasterRequest, fix: boolean): Promise<void> {
+async function runLint(req: MasterRequest, fix: undefined | DiagnosticPointer): Promise<void> {
const linter = new Linter(req, fix);
await linter.lint();
}

MODIFY
packages/@romejs/core/master/commands/test.ts
packages/@romejs/core/master/commands/test.ts
@@ -36,7 +36,7 @@ export default createMasterCommand({
async default(req: MasterRequest, commandFlags: Flags): Promise<void> {
const {reporter, master} = req;
- const files = await req.getFilesFromArgs({
+ const {paths} = await req.getFilesFromArgs({
getProjectIgnore: (project) =>
({
patterns: project.config.tests.ignore,
@@ -69,9 +69,10 @@ export default createMasterCommand({
},
],
extensions: JS_EXTENSIONS,
+ disabledDiagnosticCategory: 'tests/disabled',
});
- if (files.size === 0) {
+ if (paths.size === 0) {
reporter.warn('No tests ran');
return;
}
@@ -90,7 +91,7 @@ export default createMasterCommand({
mocks: true,
}));
- for (const [path, res] of await bundler.bundleMultiple(Array.from(files))) {
+ for (const [path, res] of await bundler.bundleMultiple(Array.from(paths))) {
tests.set(path.join(), {
code: res.entry.js.content,
sourceMap: res.entry.sourceMap.map,

MODIFY
packages/@romejs/core/master/linter/Linter.ts
packages/@romejs/core/master/linter/Linter.ts
import {MasterRequest} from '@romejs/core';
import CompilerLinter from './CompilerLinter';
import {LINTABLE_EXTENSIONS} from '@romejs/core/common/fileHandlers';
-import {AbsoluteFilePathSet} from '@romejs/path';
import DependencyGraph from '../dependencies/DependencyGraph';
+import { DiagnosticPointer } from '@romejs/diagnostics';
export default class Linter {
- constructor(req: MasterRequest, fix: boolean) {
+ constructor(req: MasterRequest, fix: undefined | DiagnosticPointer) {
this.request = req;
this.fix = fix;
}
request: MasterRequest;
- fix: boolean;
+ fix: undefined | DiagnosticPointer;
async lint(throwAlways: boolean = true) {
const {request} = this;
@@ -31,7 +31,7 @@ export default class Linter {
printer.processor.addAllowedUnusedSuppressionPrefix('bundler');
- const paths: AbsoluteFilePathSet = await request.getFilesFromArgs({
+ const {paths, projects} = await request.getFilesFromArgs({
getProjectIgnore: (project) =>
({
patterns: project.config.lint.ignore,
@@ -56,8 +56,25 @@ export default class Linter {
verb: 'linting',
configCategory: 'lint',
extensions: LINTABLE_EXTENSIONS,
+ disabledDiagnosticCategory: 'lint/disabled',
});
+ const {fix} = this;
+ const shouldFix = fix !== undefined;
+
+ if (fix !== undefined) {
+ for (const project of projects) {
+ if (!project.config.format.enabled) {
+ printer.addDiagnostic({
+ ...fix,
+ category: 'format/disabled',
+ message: 'Format is disabled for this project',
+ // TODO advice and better error message
+ });
+ }
+ }
+ }
+
printer.onBeforeFooterPrint((reporter, isError) => {
if (isError) {
let couldFix = false;
@@ -118,7 +135,7 @@ export default class Linter {
clear: true,
message: 'Analyzing files',
callback: async () => {
- const compilerLinter = new CompilerLinter(request, printer, this.fix);
+ const compilerLinter = new CompilerLinter(request, printer, shouldFix);
await compilerLinter.lint(paths);
},
},

MODIFY
packages/@romejs/diagnostics/categories.ts
packages/@romejs/diagnostics/categories.ts
@@ -21,8 +21,10 @@ export type DiagnosticCategory =
| 'compile/jsx'
| 'compile/classes'
| 'flags/invalid'
+ | 'format/disabled'
| 'internalError/request'
| 'internalError/httpServer'
+ | 'lint/disabled'
| 'lint/pendingFixes'
| 'lint/defaultExportSameBasename'
| 'lint/noMultipleSpacesInRegularExpressionLiterals'

MODIFY
packages/@romejs/js-generator/generators/statements/ForStatement.ts
packages/@romejs/js-generator/generators/statements/ForStatement.ts
@@ -32,7 +32,8 @@ export default function ForStatement(generator: Generator, node: AnyNode) {
generator.print(node.update, node);
}
+ }, {conditions: ['more-than-one-line'], indent: true, indentTrailingNewline: true});
+
generator.token(')');
generator.printBlock(node);
- }, {conditions: ['more-than-one-line']});
}

Better complaints when features disabled and we're fetching files from args