Skip to content

Commit 86af9a3

Browse files
authored
Sync ignore files on format and lint (#646)
Closes #637.
1 parent 0a227ea commit 86af9a3

File tree

8 files changed

+79
-2
lines changed

8 files changed

+79
-2
lines changed

.changeset/wet-carrots-argue.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"skuba": minor
3+
---
4+
5+
format, lint: Synchronise ignore files
6+
7+
`skuba format` and `skuba lint` will now keep `.eslintignore`, `.gitignore` and `.prettierignore` in sync. This automatically applies new exclusions like `.eslintcache` without the need for a manual `skuba configure`.

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# managed by skuba
2+
.cdk.staging/
23
.idea/
34
.serverless/
45
.vscode/
6+
cdk.out/
57
node_modules*/
68

79
/coverage*/

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ node_modules*/
1010
/tmp*/
1111

1212
# Gantry resource files support non-standard template syntax
13+
/.gantry/**/*.yaml
14+
/.gantry/**/*.yml
1315
gantry*.yaml
1416
gantry*.yml
1517
# end managed by skuba

src/cli/__snapshots__/format.int.test.ts.snap

+7-1
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,16 @@ Prettier
6262
Initialising Prettier...
6363
Detected project root: <random>
6464
Discovering files...
65-
Discovered 7 files.
65+
Discovered 10 files.
6666
Formatting files...
6767
.eslintcache
6868
parser: -
69+
.eslintignore
70+
parser: -
71+
.gitignore
72+
parser: -
73+
.prettierignore
74+
parser: -
6975
b.md
7076
parser: markdown
7177
c.json

src/cli/__snapshots__/lint.int.test.ts.snap

+7-1
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,16 @@ ESLint │ ○ d.js
6464
Prettier │ Initialising Prettier...
6565
Prettier │ Detected project root: <random>
6666
Prettier │ Discovering files...
67-
Prettier │ Discovered 7 files.
67+
Prettier │ Discovered 10 files.
6868
Prettier │ Linting files...
6969
Prettier │ .eslintcache
7070
Prettier │ parser: -
71+
Prettier │ .eslintignore
72+
Prettier │ parser: -
73+
Prettier │ .gitignore
74+
Prettier │ parser: -
75+
Prettier │ .prettierignore
76+
Prettier │ parser: -
7177
Prettier │ b.md
7278
Prettier │ parser: markdown
7379
Prettier │ c.json
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import path from 'path';
2+
3+
import fs from 'fs-extra';
4+
5+
import { log } from '../../utils/logging';
6+
import { readBaseTemplateFile } from '../../utils/template';
7+
8+
import { getDestinationManifest } from './analysis/package';
9+
import { createDestinationFileReader } from './analysis/project';
10+
import { mergeWithIgnoreFile } from './processing/ignoreFile';
11+
12+
export const refreshIgnoreFiles = async () => {
13+
const manifest = await getDestinationManifest();
14+
15+
const destinationRoot = path.dirname(manifest.path);
16+
17+
const readDestinationFile = createDestinationFileReader(destinationRoot);
18+
19+
const refreshIgnoreFile = async (filename: string) => {
20+
const [inputFile, templateFile] = await Promise.all([
21+
readDestinationFile(filename),
22+
readBaseTemplateFile(`_${filename}`),
23+
]);
24+
25+
const data = inputFile
26+
? mergeWithIgnoreFile(templateFile)(inputFile)
27+
: templateFile;
28+
29+
const filepath = path.join(destinationRoot, filename);
30+
31+
await fs.promises.writeFile(filepath, data);
32+
};
33+
34+
await Promise.all([
35+
refreshIgnoreFile('.eslintignore'),
36+
refreshIgnoreFile('.gitignore'),
37+
refreshIgnoreFile('.prettierignore'),
38+
]);
39+
};
40+
41+
export const tryRefreshIgnoreFiles = async () => {
42+
try {
43+
await refreshIgnoreFiles();
44+
} catch (err) {
45+
log.warn('Failed to refresh ignore files.');
46+
log.warn(err);
47+
}
48+
};

src/cli/format.ts

+3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import { createLogger, log } from '../utils/logging';
55

66
import { runESLint } from './adapter/eslint';
77
import { runPrettier } from './adapter/prettier';
8+
import { tryRefreshIgnoreFiles } from './configure/refreshIgnoreFiles';
89

910
export const format = async (args = process.argv) => {
11+
await tryRefreshIgnoreFiles();
12+
1013
const debug = hasDebugFlag(args);
1114

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

src/cli/lint/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { hasDebugFlag, hasSerialFlag } from '../../utils/args';
2+
import { tryRefreshIgnoreFiles } from '../configure/refreshIgnoreFiles';
23

34
import { externalLint } from './external';
45
import { internalLint } from './internal';
@@ -9,6 +10,8 @@ export const lint = async (
910
tscOutputStream: NodeJS.WritableStream | undefined = undefined,
1011
workerThreads = true,
1112
) => {
13+
await tryRefreshIgnoreFiles();
14+
1215
const opts: Input = {
1316
debug: hasDebugFlag(args),
1417
serial: hasSerialFlag(args),

0 commit comments

Comments
 (0)