Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uplift internal linting #1370

Merged
merged 17 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions .changeset/five-dancers-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'skuba': minor
---

lint: Overhaul skuba's internal linting system

Internal (skuba) linting is now promoted to a top-level tool alongside ESLint, tsc, and Prettier.

This fixes issues where skuba would not fail a `lint` check but silently make changes.
These changes may never end up being committed and causes noise when running `lint` or `format` later.

Now, lints report whether changes need to be made and are applied in `format` or autofix modes (in CI).
AaronMoat marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 24 additions & 0 deletions src/cli/__snapshots__/format.int.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

exports[`fixable 1`] = `
"
skuba lints
Refreshed .eslintignore. refresh-ignore-files
Refreshed .gitignore. refresh-ignore-files
Refreshed .prettierignore. refresh-ignore-files
Updating skuba...

Patch 7.3.1 applied.

skuba update complete.

Processed skuba lints in <random>s.

ESLint
Processed 4 files in <random>s.

Expand Down Expand Up @@ -57,12 +63,18 @@ d.js

exports[`ok --debug 1`] = `
"
skuba lints
Refreshed .eslintignore. refresh-ignore-files
Refreshed .gitignore. refresh-ignore-files
Refreshed .prettierignore. refresh-ignore-files
Updating skuba...

Patch 7.3.1 applied.

skuba update complete.

Processed skuba lints in <random>s.

ESLint
Initialising ESLint...
Processing files...
Expand Down Expand Up @@ -105,12 +117,18 @@ exports[`ok --debug 2`] = `

exports[`ok 1`] = `
"
skuba lints
Refreshed .eslintignore. refresh-ignore-files
Refreshed .gitignore. refresh-ignore-files
Refreshed .prettierignore. refresh-ignore-files
Updating skuba...

Patch 7.3.1 applied.

skuba update complete.

Processed skuba lints in <random>s.

ESLint
Processed 2 files in <random>s.

Expand All @@ -126,12 +144,18 @@ exports[`ok 2`] = `

exports[`unfixable 1`] = `
"
skuba lints
Refreshed .eslintignore. refresh-ignore-files
Refreshed .gitignore. refresh-ignore-files
Refreshed .prettierignore. refresh-ignore-files
Updating skuba...

Patch 7.3.1 applied.

skuba update complete.

Processed skuba lints in <random>s.

ESLint
Processed 2 files in <random>s.

Expand Down
44 changes: 20 additions & 24 deletions src/cli/__snapshots__/lint.int.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

exports[`fixable 1`] = `
"
Updating skuba...

Patch 7.3.1 applied.

skuba update complete.

ESLint │ Processed 4 files in <random>s.
ESLint │
<random>/a/a/a.mjs
Expand All @@ -23,14 +17,16 @@ ESLint │
3 errors and 0 warnings potentially fixable with the \`--fix\` option.

Prettier │ Processed 8 files in <random>s.
Prettier │ Flagged 3 files:
Prettier │ Flagged 4 files:
Prettier │ b.md
Prettier │ c.json
Prettier │ d.js
Prettier │ package.json
tsc │ TSFILE: <random>/lib/tsconfig.tsbuildinfo
tsc │ tsc --noEmit exited with code 0

ESLint, Prettier found issues that require triage.
skuba │ Processed skuba lints in <random>s.
"
`;

Expand Down Expand Up @@ -67,19 +63,28 @@ Options: {
b.md
c.json
d.js
package.json
\`\`\`
",
]
`;

exports[`ok --debug 1`] = `
exports[`needs patches 1`] = `
"
Updating skuba...

Patch 7.3.1 applied.
ESLint │ Processed 2 files in <random>s.
Prettier │ Processed 6 files in <random>s.
tsc │ TSFILE: <random>/lib/tsconfig.tsbuildinfo
tsc │ tsc --noEmit exited with code 0
skuba │ skuba has patches to apply. Run yarn skuba format to run them. skuba-patches
skuba │ Some skuba lints failed. Try running yarn skuba format to fix them. skuba-lint
skuba │ Processed skuba lints in <random>s.
"
`;

skuba update complete.
exports[`needs patches 2`] = `[]`;

exports[`ok --debug 1`] = `
"
ESLint │ Initialising ESLint...
ESLint │ Processing files...
ESLint │ Processed 2 files in <random>s.
Expand Down Expand Up @@ -139,36 +144,26 @@ tsc │ printTime time: <random>s
tsc │ Emit time: <random>s
tsc │ Total time: <random>s
tsc │ tsc --extendedDiagnostics --noEmit exited with code 0
skuba │ Processed skuba lints in <random>s.
"
`;

exports[`ok --debug 2`] = `[]`;

exports[`ok 1`] = `
"
Updating skuba...

Patch 7.3.1 applied.

skuba update complete.

ESLint │ Processed 2 files in <random>s.
Prettier │ Processed 6 files in <random>s.
tsc │ TSFILE: <random>/lib/tsconfig.tsbuildinfo
tsc │ tsc --noEmit exited with code 0
skuba │ Processed skuba lints in <random>s.
"
`;

exports[`ok 2`] = `[]`;

exports[`unfixable 1`] = `
"
Updating skuba...

Patch 7.3.1 applied.

skuba update complete.

ESLint │ Processed 2 files in <random>s.
ESLint │
<random>/a/a/a.ts
Expand All @@ -193,6 +188,7 @@ tsc │ TSFILE: <random>/lib/tsconfig.tsbuildinfo
tsc │ tsc --noEmit exited with code 2

ESLint, Prettier, tsc found issues that require triage.
skuba │ Processed skuba lints in <random>s.
"
`;

Expand Down
57 changes: 0 additions & 57 deletions src/cli/configure/refreshIgnoreFiles.ts

This file was deleted.

10 changes: 6 additions & 4 deletions src/cli/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import { createLogger, log } from '../utils/logging';

import { runESLint } from './adapter/eslint';
import { runPrettier } from './adapter/prettier';
import { tryRefreshIgnoreFiles } from './configure/refreshIgnoreFiles';
import { upgradeSkuba } from './configure/upgrade';
import { internalLint } from './lint/internal';

export const format = async (args = process.argv.slice(2)): Promise<void> => {
await Promise.all([tryRefreshIgnoreFiles(), upgradeSkuba()]);
log.plain(chalk.blueBright('skuba lints'));
const internal = await internalLint('format', { debug: false, serial: true });

const debug = hasDebugFlag(args);
AaronMoat marked this conversation as resolved.
Show resolved Hide resolved
const logger = createLogger(debug);

log.newline();
log.plain(chalk.magenta('ESLint'));

const eslint = await runESLint('format', logger);
Expand All @@ -23,13 +24,14 @@ export const format = async (args = process.argv.slice(2)): Promise<void> => {

const prettier = await runPrettier('format', logger);

if (eslint.ok && prettier.ok) {
if (eslint.ok && prettier.ok && internal.ok) {
return;
}

const tools = [
...(eslint.ok ? [] : ['ESLint']),
...(prettier.ok ? [] : ['Prettier']),
...(internal.ok ? [] : ['skuba']),
];

log.newline();
Expand Down
28 changes: 21 additions & 7 deletions src/cli/lint.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import fs, { copy } from 'fs-extra';
import git from 'isomorphic-git';

import { Buildkite } from '..';
import type { Logger } from '../utils/logging';
import { getSkubaVersion } from '../utils/version';

import { lint } from './lint';
import { refreshIgnoreFiles } from './lint/internalLints/refreshIgnoreFiles';

jest.setTimeout(30_000);

jest.mock('../utils/version');

const buildkiteAnnotate = jest.spyOn(Buildkite, 'annotate').mockResolvedValue();

const stdoutMock = jest.fn();
Expand Down Expand Up @@ -64,8 +69,13 @@ const stdout = (randomMatcher: RegExp) => {

const prepareTempDirectory = async (baseDir: string, tempDir: string) => {
await copy(baseDir, tempDir);

process.chdir(tempDir);
const result = await refreshIgnoreFiles('format', {
bold: jest.fn(),
dim: jest.fn(),
warn: jest.fn(),
} as unknown as Logger);
expect(result.ok).toBe(true);
};

const originalCwd = process.cwd();
Expand Down Expand Up @@ -100,16 +110,20 @@ afterAll(() => {
interface Args {
args: string[];
base: string;
skubaVersion: string;
exitCode: number | undefined;
}

test.each`
description | args | base | exitCode
${'fixable'} | ${[]} | ${'fixable'} | ${1}
${'ok'} | ${[]} | ${'ok'} | ${undefined}
${'ok --debug'} | ${['--debug']} | ${'ok'} | ${undefined}
${'unfixable'} | ${[]} | ${'unfixable'} | ${1}
`('$description', async ({ args, base, exitCode }: Args) => {
description | args | base | skubaVersion | exitCode
${'fixable'} | ${[]} | ${'fixable'} | ${'0.0.0'} | ${1}
${'ok'} | ${[]} | ${'ok'} | ${'0.0.0'} | ${undefined}
${'ok --debug'} | ${['--debug']} | ${'ok'} | ${'0.0.0'} | ${undefined}
${'unfixable'} | ${[]} | ${'unfixable'} | ${'0.0.0'} | ${1}
${'needs patches'} | ${[]} | ${'ok'} | ${'1.0.0'} | ${1}
`('$description', async ({ args, base, skubaVersion, exitCode }: Args) => {
jest.mocked(getSkubaVersion).mockResolvedValue(skubaVersion);

const baseDir = path.join(BASE_PATH, base);

const tempDir = path.join(
Expand Down
Loading