Content-Length: 493115 | pFad | http://github.com/forteddyt/azure-rest-api-specs/commit/d8fea3be3e325648fa72fbd251191de9af5d049a

3B [TypeSpecValidation] Add basic suppressions (#29133) · forteddyt/azure-rest-api-specs@d8fea3b · GitHub
Skip to content

Commit d8fea3b

Browse files
authored
[TypeSpecValidation] Add basic suppressions (Azure#29133)
- Fixes Azure#29131
1 parent 60161e2 commit d8fea3b

File tree

5 files changed

+42
-7
lines changed

5 files changed

+42
-7
lines changed

eng/tools/suppressions/src/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { access, constants, readFile } from "fs/promises";
1+
import { access, constants, lstat, readFile } from "fs/promises";
22
import { minimatch } from "minimatch";
33
import { dirname, join, resolve, sep } from "path";
44
import { sep as posixSep } from "path/posix";
@@ -9,11 +9,14 @@ import { fromError } from "zod-validation-error";
99

1010
function getUsage(): string {
1111
return (
12-
" Usage: npx get-suppressions <tool-name> <path-to-file>\n" +
13-
"Returns: JSON array of suppressions, with specified tool name, applying to file (may be empty)\n" +
12+
" Usage: npx get-suppressions <tool-name> <path-to-file-or-directory>\n" +
13+
"Returns: JSON array of suppressions, with specified tool name, applying to file or directory (may be empty)\n" +
1414
"\n" +
1515
"Example: npx get-suppressions TypeSpecRequirement specification/foo/data-plane/Foo/stable/2023-01-01/Foo.json\n" +
16-
'Returns: [{"tool":"TypeSpecRequirement","path":"data-plane/Foo/stable/2023-01-01/*.json","reason":"foo"}]\n'
16+
'Returns: [{"tool":"TypeSpecRequirement","path":"data-plane/Foo/stable/2023-01-01/*.json","reason":"foo"}]\n' +
17+
"\n" +
18+
"Example: npx get-suppressions TypeSpecValidation specification/foo/Microsoft.Foo\n" +
19+
'Returns: [{"tool":"TypeSpecValidation","path":"**","reason":"foo"}]\n'
1720
);
1821
}
1922

@@ -51,7 +54,7 @@ export async function main() {
5154
* "suppressions.yaml", parses and validates the contents, and returns the suppressions matching the tool and path.
5255
*
5356
* @param tool Name of tool. Matched against property "tool" in suppressions.yaml.
54-
* @param path Path to file under analysis.
57+
* @param path Path to file or directory under analysis.
5558
* @returns Array of suppressions matching tool and path (may be empty).
5659
*
5760
* @example
@@ -161,7 +164,9 @@ export function _getSuppressionsFromYaml(
161164
async function findSuppressionsYaml(path: string): Promise<string | undefined> {
162165
path = resolve(path);
163166

164-
let currentDirectory: string = dirname(path);
167+
const stats = await lstat(path);
168+
let currentDirectory: string = stats.isDirectory() ? path : dirname(path);
169+
165170
while (true) {
166171
const suppressionsFile: string = join(currentDirectory, "suppressions.yaml");
167172
try {

eng/tools/suppressions/test/index.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ test("one suppression match", () => {
3737
]);
3838
});
3939

40+
test("one suppression match directory", () => {
41+
const suppressions: Suppression[] = _getSuppressionsFromYaml(
42+
"TestTool",
43+
"Microsoft.Foo",
44+
"suppressions.yaml",
45+
'- tool: TestTool\n path: "**"\n reason: test',
46+
);
47+
expect(suppressions).toEqual([
48+
{
49+
tool: "TestTool",
50+
path: "**",
51+
reason: "test",
52+
},
53+
]);
54+
});
55+
4056
test("globstar matching", () => {
4157
const suppressions: Suppression[] = _getSuppressionsFromYaml(
4258
"TestTool",

eng/tools/typespec-validation/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"dependencies": {
1111
"globby": "^14.0.1",
1212
"simple-git": "^3.24.0",
13+
"suppressions": "file:../suppressions",
1314
"yaml": "^2.4.2"
1415
},
1516
"devDependencies": {
@@ -20,7 +21,7 @@
2021
},
2122
"scripts": {
2223
"build": "tsc",
23-
"postinstall": "npm run build",
24+
"postinstall": "cd ../suppressions && npm run build && cd ../typespec-validation && npm run build",
2425
"test": "npm run build && mocha --recursive --exit"
2526
},
2627
"engines": {

eng/tools/typespec-validation/src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { FormatRule } from "./rules/format.js";
77
import { LinterRulesetRule } from "./rules/linter-ruleset.js";
88
import { NpmPrefixRule } from "./rules/npm-prefix.js";
99
import { TsvRunnerHost } from "./tsv-runner-host.js";
10+
import { getSuppressions, Suppression } from "suppressions";
1011

1112
export async function main() {
1213
const host = new TsvRunnerHost();
@@ -31,6 +32,13 @@ export async function main() {
3132
}
3233
console.log("Running TypeSpecValidation on folder: ", absolutePath);
3334

35+
const suppressions: Suppression[] = await getSuppressions("TypeSpecValidation", absolutePath);
36+
if (suppressions && suppressions[0]) {
37+
// Use reason from first matching suppression and ignore rest
38+
console.log(` Suppressed: ${suppressions[0].reason}`);
39+
return;
40+
}
41+
3442
const rules = [
3543
new FolderStructureRule(),
3644
new NpmPrefixRule(),

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/forteddyt/azure-rest-api-specs/commit/d8fea3be3e325648fa72fbd251191de9af5d049a

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy