Skip to content

Commit 0b051ef

Browse files
committed
style: format with prettier
Signed-off-by: Simon Scatton <sscatton@nvidia.com>
1 parent d9c15a5 commit 0b051ef

5 files changed

Lines changed: 194 additions & 154 deletions

File tree

‎spdx-check/index.mjs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ function main() {
5959
const exclude = patterns(process.env.INPUT_EXCLUDE);
6060
const files = listFiles({ include, exclude, cwd });
6161
const failures = findFailures(files, cwd);
62-
const result =
63-
`Checked ${files.length} files, ${failures.length} missing ${LICENSE}`;
62+
const result = `Checked ${files.length} files, ${failures.length} missing ${LICENSE}`;
6463
failures.forEach((src) => console.log(annotation(src)));
6564
console.log(result);
6665
const summary = process.env.GITHUB_STEP_SUMMARY;

‎spdx-check/test/files.test.mjs‎

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,93 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3-
import { test } from 'node:test';
4-
import assert from 'node:assert/strict';
5-
import { headerSource, listFiles } from '../files.mjs';
6-
import { makeRepo, writeFiles } from './repo.mjs';
3+
import { test } from "node:test";
4+
import assert from "node:assert/strict";
5+
import { headerSource, listFiles } from "../files.mjs";
6+
import { makeRepo, writeFiles } from "./repo.mjs";
77

88
// Listing only looks at paths, so every file can be empty.
99
function repo(paths) {
10-
return makeRepo(Object.fromEntries(paths.map((path) => [path, ''])));
10+
return makeRepo(Object.fromEntries(paths.map((path) => [path, ""])));
1111
}
1212

1313
function sorted(list) {
1414
return [...list].sort();
1515
}
1616

17-
test('*.py matches at root and at depth', () => {
18-
const cwd = repo(['a.py', 'pkg/b.py', 'pkg/sub/c.py', 'README.md']);
19-
const files = listFiles({ include: ['*.py'], cwd });
20-
assert.deepEqual(sorted(files), ['a.py', 'pkg/b.py', 'pkg/sub/c.py']);
17+
test("*.py matches at root and at depth", () => {
18+
const cwd = repo(["a.py", "pkg/b.py", "pkg/sub/c.py", "README.md"]);
19+
const files = listFiles({ include: ["*.py"], cwd });
20+
assert.deepEqual(sorted(files), ["a.py", "pkg/b.py", "pkg/sub/c.py"]);
2121
});
2222

23-
test('Dockerfile* matches root-level files only', () => {
24-
const cwd = repo(['Dockerfile', 'Dockerfile.dev', 'deploy/Dockerfile']);
25-
const files = listFiles({ include: ['Dockerfile*'], cwd });
26-
assert.deepEqual(sorted(files), ['Dockerfile', 'Dockerfile.dev']);
23+
test("Dockerfile* matches root-level files only", () => {
24+
const cwd = repo(["Dockerfile", "Dockerfile.dev", "deploy/Dockerfile"]);
25+
const files = listFiles({ include: ["Dockerfile*"], cwd });
26+
assert.deepEqual(sorted(files), ["Dockerfile", "Dockerfile.dev"]);
2727
});
2828

29-
test('*/Dockerfile* matches nested files only', () => {
30-
const cwd = repo(['Dockerfile', 'deploy/Dockerfile', 'deploy/Dockerfile.prod']);
31-
const files = listFiles({ include: ['*/Dockerfile*'], cwd });
32-
assert.deepEqual(sorted(files), ['deploy/Dockerfile', 'deploy/Dockerfile.prod']);
29+
test("*/Dockerfile* matches nested files only", () => {
30+
const cwd = repo([
31+
"Dockerfile",
32+
"deploy/Dockerfile",
33+
"deploy/Dockerfile.prod",
34+
]);
35+
const files = listFiles({ include: ["*/Dockerfile*"], cwd });
36+
assert.deepEqual(sorted(files), [
37+
"deploy/Dockerfile",
38+
"deploy/Dockerfile.prod",
39+
]);
3340
});
3441

35-
test('scripts/bin/* matches an extensionless file', () => {
36-
const cwd = repo(['scripts/bin/run', 'scripts/other']);
37-
const files = listFiles({ include: ['scripts/bin/*'], cwd });
38-
assert.deepEqual(files, ['scripts/bin/run']);
42+
test("scripts/bin/* matches an extensionless file", () => {
43+
const cwd = repo(["scripts/bin/run", "scripts/other"]);
44+
const files = listFiles({ include: ["scripts/bin/*"], cwd });
45+
assert.deepEqual(files, ["scripts/bin/run"]);
3946
});
4047

41-
test('excludes remove matching files', () => {
42-
const cwd = repo(['a.py', 'third_party/x.py', 'proto/m_pb2.py']);
48+
test("excludes remove matching files", () => {
49+
const cwd = repo(["a.py", "third_party/x.py", "proto/m_pb2.py"]);
4350
const files = listFiles({
44-
include: ['*.py'],
45-
exclude: ['third_party/*', '*_pb2.py'],
51+
include: ["*.py"],
52+
exclude: ["third_party/*", "*_pb2.py"],
4653
cwd,
4754
});
48-
assert.deepEqual(files, ['a.py']);
55+
assert.deepEqual(files, ["a.py"]);
4956
});
5057

51-
test('exclude patterns keep their own pathspec magic', () => {
52-
const cwd = repo(['src/z.go', 'vendor/y.go', 'vendor/a/x.go']);
53-
const files = listFiles({ include: ['*.go'], exclude: [':(glob)vendor/**'], cwd });
54-
assert.deepEqual(files, ['src/z.go']);
58+
test("exclude patterns keep their own pathspec magic", () => {
59+
const cwd = repo(["src/z.go", "vendor/y.go", "vendor/a/x.go"]);
60+
const files = listFiles({
61+
include: ["*.go"],
62+
exclude: [":(glob)vendor/**"],
63+
cwd,
64+
});
65+
assert.deepEqual(files, ["src/z.go"]);
5566
});
5667

57-
test('untracked files are ignored', () => {
58-
const cwd = repo(['a.py']);
59-
writeFiles(cwd, { 'b.py': '' });
60-
assert.deepEqual(listFiles({ include: ['*.py'], cwd }), ['a.py']);
68+
test("untracked files are ignored", () => {
69+
const cwd = repo(["a.py"]);
70+
writeFiles(cwd, { "b.py": "" });
71+
assert.deepEqual(listFiles({ include: ["*.py"], cwd }), ["a.py"]);
6172
});
6273

63-
test('multiple include patterns combine', () => {
64-
const cwd = repo(['a.py', 'b.mjs', 'c.md']);
65-
const files = listFiles({ include: ['*.py', '*.mjs'], cwd });
66-
assert.deepEqual(sorted(files), ['a.py', 'b.mjs']);
74+
test("multiple include patterns combine", () => {
75+
const cwd = repo(["a.py", "b.mjs", "c.md"]);
76+
const files = listFiles({ include: ["*.py", "*.mjs"], cwd });
77+
assert.deepEqual(sorted(files), ["a.py", "b.mjs"]);
6778
});
6879

69-
test('headerSource returns the sidecar when it exists', () => {
70-
const cwd = repo(['x.json', 'x.json.license']);
71-
assert.equal(headerSource('x.json', cwd), 'x.json.license');
80+
test("headerSource returns the sidecar when it exists", () => {
81+
const cwd = repo(["x.json", "x.json.license"]);
82+
assert.equal(headerSource("x.json", cwd), "x.json.license");
7283
});
7384

74-
test('headerSource returns the path when there is no sidecar', () => {
75-
const cwd = repo(['y.json']);
76-
assert.equal(headerSource('y.json', cwd), 'y.json');
85+
test("headerSource returns the path when there is no sidecar", () => {
86+
const cwd = repo(["y.json"]);
87+
assert.equal(headerSource("y.json", cwd), "y.json");
7788
});
7889

79-
test('headerSource works for nested paths', () => {
80-
const cwd = repo(['conf/x.json', 'conf/x.json.license']);
81-
assert.equal(headerSource('conf/x.json', cwd), 'conf/x.json.license');
90+
test("headerSource works for nested paths", () => {
91+
const cwd = repo(["conf/x.json", "conf/x.json.license"]);
92+
assert.equal(headerSource("conf/x.json", cwd), "conf/x.json.license");
8293
});

‎spdx-check/test/header.test.mjs‎

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,101 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3-
import { test } from 'node:test';
4-
import assert from 'node:assert/strict';
5-
import { hasHeaderLines, hasSpdxHeader } from '../header.mjs';
3+
import { test } from "node:test";
4+
import assert from "node:assert/strict";
5+
import { hasHeaderLines, hasSpdxHeader } from "../header.mjs";
66

7-
const ID = 'SPDX-License-Identifier: Apache-2.0';
7+
const ID = "SPDX-License-Identifier: Apache-2.0";
88

99
function check(text) {
1010
return hasSpdxHeader(Buffer.from(text));
1111
}
1212

1313
function filler(n) {
14-
return 'x\n'.repeat(n);
14+
return "x\n".repeat(n);
1515
}
1616

17-
test('empty buffer passes', () => {
17+
test("empty buffer passes", () => {
1818
assert.equal(hasSpdxHeader(Buffer.alloc(0)), true);
1919
});
2020

21-
test('hash comment passes', () => {
21+
test("hash comment passes", () => {
2222
assert.equal(check(`# ${ID}\nprint("hi")\n`), true);
2323
});
2424

25-
test('double-slash comment passes', () => {
25+
test("double-slash comment passes", () => {
2626
assert.equal(check(`// ${ID}\nconsole.log(1);\n`), true);
2727
});
2828

29-
test('multi-line block comment passes', () => {
29+
test("multi-line block comment passes", () => {
3030
assert.equal(check(`/*\n * Copyright Foo\n * ${ID}\n */\nint x;\n`), true);
3131
});
3232

33-
test('single-line block comment passes', () => {
33+
test("single-line block comment passes", () => {
3434
assert.equal(check(`/* ${ID} */\nint x;\n`), true);
3535
});
3636

37-
test('html comment passes', () => {
37+
test("html comment passes", () => {
3838
assert.equal(check(`<!-- ${ID} -->\n<p>hi</p>\n`), true);
3939
});
4040

41-
test('shebang then header passes', () => {
41+
test("shebang then header passes", () => {
4242
assert.equal(check(`#!/usr/bin/env python3\n# ${ID}\n`), true);
4343
});
4444

45-
test('header on line 10 passes', () => {
45+
test("header on line 10 passes", () => {
4646
assert.equal(check(`${filler(9)}# ${ID}\n`), true);
4747
});
4848

49-
test('header on line 11 fails', () => {
49+
test("header on line 11 fails", () => {
5050
assert.equal(check(`${filler(10)}# ${ID}\n`), false);
5151
});
5252

53-
test('CRLF file passes', () => {
53+
test("CRLF file passes", () => {
5454
assert.equal(check(`#!/bin/sh\r\n# ${ID}\r\necho hi\r\n`), true);
5555
});
5656

57-
test('file without header fails', () => {
57+
test("file without header fails", () => {
5858
assert.equal(check('print("hi")\n'), false);
5959
});
6060

61-
test('MIT fails', () => {
62-
assert.equal(check('# SPDX-License-Identifier: MIT\n'), false);
61+
test("MIT fails", () => {
62+
assert.equal(check("# SPDX-License-Identifier: MIT\n"), false);
6363
});
6464

65-
test('Apache-2.0-only is rejected', () => {
65+
test("Apache-2.0-only is rejected", () => {
6666
assert.equal(check(`# ${ID}-only\n`), false);
6767
});
6868

69-
test('Apache-2.0 OR MIT is rejected', () => {
69+
test("Apache-2.0 OR MIT is rejected", () => {
7070
assert.equal(check(`# ${ID} OR MIT\n`), false);
7171
});
7272

73-
test('Apache-2.0 AND MIT is rejected', () => {
73+
test("Apache-2.0 AND MIT is rejected", () => {
7474
assert.equal(check(`# ${ID} AND MIT\n`), false);
7575
});
7676

77-
test('Apache-2.0 WITH an exception is rejected', () => {
77+
test("Apache-2.0 WITH an exception is rejected", () => {
7878
assert.equal(check(`# ${ID} WITH LLVM-exception\n`), false);
7979
});
8080

81-
test('UTF-16 BOM bytes before header still pass', () => {
82-
const buf = Buffer.concat([Buffer.from([0xff, 0xfe]), Buffer.from(`# ${ID}\n`)]);
81+
test("UTF-16 BOM bytes before header still pass", () => {
82+
const buf = Buffer.concat([
83+
Buffer.from([0xff, 0xfe]),
84+
Buffer.from(`# ${ID}\n`),
85+
]);
8386
assert.equal(hasSpdxHeader(buf), true);
8487
});
8588

86-
test('Latin-1 byte before header still passes', () => {
89+
test("Latin-1 byte before header still passes", () => {
8790
const buf = Buffer.concat([
88-
Buffer.from('# Caf'),
91+
Buffer.from("# Caf"),
8992
Buffer.from([0xe9]),
9093
Buffer.from(`\n# ${ID}\n`),
9194
]);
9295
assert.equal(hasSpdxHeader(buf), true);
9396
});
9497

95-
test('NUL bytes around header still pass', () => {
98+
test("NUL bytes around header still pass", () => {
9699
const buf = Buffer.concat([
97100
Buffer.from([0x00, 0x00, 0x0a]),
98101
Buffer.from(`# ${ID}\n`),
@@ -101,7 +104,7 @@ test('NUL bytes around header still pass', () => {
101104
assert.equal(hasSpdxHeader(buf), true);
102105
});
103106

104-
test('header lines are complete only after the tenth newline', () => {
107+
test("header lines are complete only after the tenth newline", () => {
105108
assert.equal(hasHeaderLines(Buffer.from(filler(9))), false);
106109
assert.equal(hasHeaderLines(Buffer.from(`${filler(9)}x`)), false);
107110
assert.equal(hasHeaderLines(Buffer.from(filler(10))), true);

0 commit comments

Comments
 (0)