Commit c35dc9a0 by Steven Vachon Committed by GitHub

@grafana/toolkit: lint fix option now writes changes to disk (#22278)

parent e08b39d4
...@@ -10,7 +10,7 @@ import { constants as fsConstants, promises as fs } from 'fs'; ...@@ -10,7 +10,7 @@ import { constants as fsConstants, promises as fs } from 'fs';
import { CLIEngine } from 'eslint'; import { CLIEngine } from 'eslint';
import { bundlePlugin as bundleFn, PluginBundleOptions } from './plugin/bundle'; import { bundlePlugin as bundleFn, PluginBundleOptions } from './plugin/bundle';
const { copyFile } = fs; const { access, copyFile } = fs;
const { COPYFILE_EXCL } = fsConstants; const { COPYFILE_EXCL } = fsConstants;
const rimraf = promisify(rimrafCallback); const rimraf = promisify(rimrafCallback);
...@@ -62,10 +62,10 @@ const getTypescriptSources = () => globby(resolvePath(process.cwd(), 'src/**/*.+ ...@@ -62,10 +62,10 @@ const getTypescriptSources = () => globby(resolvePath(process.cwd(), 'src/**/*.+
// @ts-ignore // @ts-ignore
const getStylesSources = () => globby(resolvePath(process.cwd(), 'src/**/*.+(scss|css)')); const getStylesSources = () => globby(resolvePath(process.cwd(), 'src/**/*.+(scss|css)'));
export const lintPlugin = useSpinner<Fixable>('Linting', async ({ fix }) => { export const lintPlugin = useSpinner<Fixable>('Linting', async ({ fix } = {}) => {
try { try {
// Show a warning if the tslint file exists // Show a warning if the tslint file exists
await fs.access(resolvePath(process.cwd(), 'tslint.json')); await access(resolvePath(process.cwd(), 'tslint.json'));
console.log('\n'); console.log('\n');
console.log('--------------------------------------------------------------'); console.log('--------------------------------------------------------------');
console.log('NOTE: @grafana/toolkit has migrated to use eslint'); console.log('NOTE: @grafana/toolkit has migrated to use eslint');
...@@ -91,7 +91,13 @@ export const lintPlugin = useSpinner<Fixable>('Linting', async ({ fix }) => { ...@@ -91,7 +91,13 @@ export const lintPlugin = useSpinner<Fixable>('Linting', async ({ fix }) => {
fix, fix,
}); });
const { errorCount, results, warningCount } = cli.executeOnFiles(await getTypescriptSources()); const report = cli.executeOnFiles(await getTypescriptSources());
if (fix) {
CLIEngine.outputFixes(report);
}
const { errorCount, results, warningCount } = report;
if (errorCount > 0 || warningCount > 0) { if (errorCount > 0 || warningCount > 0) {
const formatter = cli.getFormatter(); const formatter = cli.getFormatter();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment