@typespec/library-linter 0.44.0 → 0.45.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/lib.d.ts +16 -1
- package/dist/src/lib.d.ts.map +1 -1
- package/dist/src/lib.js +6 -0
- package/dist/src/lib.js.map +1 -1
- package/dist/src/linter.d.ts.map +1 -1
- package/dist/src/linter.js +30 -0
- package/dist/src/linter.js.map +1 -1
- package/package.json +5 -4
package/dist/src/lib.d.ts
CHANGED
|
@@ -7,21 +7,36 @@ export declare const libDef: {
|
|
|
7
7
|
readonly default: import("@typespec/compiler").CallableMessage<["type", "name"]>;
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
|
+
readonly "missing-signature": {
|
|
11
|
+
readonly severity: "warning";
|
|
12
|
+
readonly messages: {
|
|
13
|
+
readonly default: import("@typespec/compiler").CallableMessage<["decName", "decName"]>;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
10
16
|
};
|
|
11
17
|
};
|
|
12
18
|
declare const lib: import("@typespec/compiler").TypeSpecLibrary<{
|
|
13
19
|
"missing-namespace": {
|
|
14
20
|
readonly default: import("@typespec/compiler").CallableMessage<["type", "name"]>;
|
|
15
21
|
};
|
|
22
|
+
"missing-signature": {
|
|
23
|
+
readonly default: import("@typespec/compiler").CallableMessage<["decName", "decName"]>;
|
|
24
|
+
};
|
|
16
25
|
}, Record<string, any>>;
|
|
17
|
-
export declare const reportDiagnostic: <C extends "missing-namespace", M extends keyof {
|
|
26
|
+
export declare const reportDiagnostic: <C extends "missing-namespace" | "missing-signature", M extends keyof {
|
|
18
27
|
"missing-namespace": {
|
|
19
28
|
readonly default: import("@typespec/compiler").CallableMessage<["type", "name"]>;
|
|
20
29
|
};
|
|
30
|
+
"missing-signature": {
|
|
31
|
+
readonly default: import("@typespec/compiler").CallableMessage<["decName", "decName"]>;
|
|
32
|
+
};
|
|
21
33
|
}[C]>(program: import("@typespec/compiler").Program, diag: import("@typespec/compiler").DiagnosticReport<{
|
|
22
34
|
"missing-namespace": {
|
|
23
35
|
readonly default: import("@typespec/compiler").CallableMessage<["type", "name"]>;
|
|
24
36
|
};
|
|
37
|
+
"missing-signature": {
|
|
38
|
+
readonly default: import("@typespec/compiler").CallableMessage<["decName", "decName"]>;
|
|
39
|
+
};
|
|
25
40
|
}, C, M>) => void;
|
|
26
41
|
export type OpenAPILibrary = typeof lib;
|
|
27
42
|
export {};
|
package/dist/src/lib.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;CAgBT,CAAC;AACX,QAAA,MAAM,GAAG;;;;;;;uBAAgC,CAAC;AAC1C,eAAO,MAAQ,gBAAgB;;;;;;;;;;;;;;iBAAQ,CAAC;AAExC,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,CAAC"}
|
package/dist/src/lib.js
CHANGED
|
@@ -8,6 +8,12 @@ export const libDef = {
|
|
|
8
8
|
default: paramMessage `${"type"} '${"name"}' is not in a namespace. This is bad practice for a published library.`,
|
|
9
9
|
},
|
|
10
10
|
},
|
|
11
|
+
"missing-signature": {
|
|
12
|
+
severity: "warning",
|
|
13
|
+
messages: {
|
|
14
|
+
default: paramMessage `Decorator function $${"decName"} is missing a decorator declaration. Add "extern dec ${"decName"}(...args);" to the library tsp.`,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
11
17
|
},
|
|
12
18
|
};
|
|
13
19
|
const lib = createTypeSpecLibrary(libDef);
|
package/dist/src/lib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEzE,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,IAAI,EAAE,0BAA0B;IAChC,WAAW,EAAE;QACX,mBAAmB,EAAE;YACnB,QAAQ,EAAE,SAAS;YACnB,QAAQ,EAAE;gBACR,OAAO,EAAE,YAAY,CAAA,GAAG,MAAM,KAAK,MAAM,wEAAwE;aAClH;SACF;KACF;CACO,CAAC;AACX,MAAM,GAAG,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAC1C,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,GAAG,GAAG,CAAC"}
|
|
1
|
+
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEzE,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,IAAI,EAAE,0BAA0B;IAChC,WAAW,EAAE;QACX,mBAAmB,EAAE;YACnB,QAAQ,EAAE,SAAS;YACnB,QAAQ,EAAE;gBACR,OAAO,EAAE,YAAY,CAAA,GAAG,MAAM,KAAK,MAAM,wEAAwE;aAClH;SACF;QACD,mBAAmB,EAAE;YACnB,QAAQ,EAAE,SAAS;YACnB,QAAQ,EAAE;gBACR,OAAO,EAAE,YAAY,CAAA,uBAAuB,SAAS,wDAAwD,SAAS,iCAAiC;aACxJ;SACF;KACF;CACO,CAAC;AACX,MAAM,GAAG,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAC1C,MAAM,CAAC,MAAM,EAAE,gBAAgB,EAAE,GAAG,GAAG,CAAC"}
|
package/dist/src/linter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linter.d.ts","sourceRoot":"","sources":["../../src/linter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,OAAO,
|
|
1
|
+
{"version":3,"file":"linter.d.ts","sourceRoot":"","sources":["../../src/linter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,OAAO,EAAsC,MAAM,oBAAoB,CAAC;AAG5F,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,QAK3C"}
|
package/dist/src/linter.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { SyntaxKind } from "@typespec/compiler";
|
|
1
2
|
import { reportDiagnostic } from "./lib.js";
|
|
2
3
|
export function $onValidate(program) {
|
|
3
4
|
const root = program.checker.getGlobalNamespaceType();
|
|
4
5
|
validateNoExportAtRoot(program, root);
|
|
6
|
+
validateDecoratorSignature(program);
|
|
5
7
|
}
|
|
6
8
|
function validateNoExportAtRoot(program, root) {
|
|
7
9
|
var _a, _b;
|
|
@@ -37,4 +39,32 @@ function validateNoExportAtRoot(program, root) {
|
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
}
|
|
42
|
+
const excludeDecoratorSignature = new Set([
|
|
43
|
+
"@docFromComment",
|
|
44
|
+
"@indexer",
|
|
45
|
+
"@test",
|
|
46
|
+
"@list",
|
|
47
|
+
"@resourceTypeForKeyParam", // TODO check if we actually need this one https://github.com/microsoft/typespec/issues/1981
|
|
48
|
+
]);
|
|
49
|
+
function validateDecoratorSignature(program) {
|
|
50
|
+
function navigate(sym) {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
if (sym.flags & 16384 /* SymbolFlags.Decorator */) {
|
|
53
|
+
const hasSignature = sym.declarations.some((x) => x.kind === SyntaxKind.DecoratorDeclarationStatement);
|
|
54
|
+
if (!hasSignature && !excludeDecoratorSignature.has(sym.name)) {
|
|
55
|
+
reportDiagnostic(program, {
|
|
56
|
+
code: "missing-signature",
|
|
57
|
+
format: { decName: sym.name.slice(1) },
|
|
58
|
+
target: sym,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const exp of (_b = (_a = sym.exports) === null || _a === void 0 ? void 0 : _a.values()) !== null && _b !== void 0 ? _b : []) {
|
|
63
|
+
navigate(exp);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
for (const jsFile of program.jsSourceFiles.values()) {
|
|
67
|
+
navigate(jsFile.symbol);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
40
70
|
//# sourceMappingURL=linter.js.map
|
package/dist/src/linter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linter.js","sourceRoot":"","sources":["../../src/linter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"linter.js","sourceRoot":"","sources":["../../src/linter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,UAAU,EAAQ,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAQ,CAAC,sBAAsB,EAAE,CAAC;IAEvD,sBAAsB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACtC,0BAA0B,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC;AAED,SAAS,sBAAsB,CAAC,OAAgB,EAAE,IAAe;;IAC/D,SAAS,WAAW,CAAC,KAA4C;;QAC/D,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE;YACjC,gBAAgB,CAAC,OAAO,EAAE;gBACxB,IAAI,EAAE,mBAAmB;gBACzB,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,MAAA,IAAI,CAAC,IAAI,mCAAI,EAAE,EAAE;gBAClD,MAAM,EAAE,IAAI;aACb,CAAC,CAAC;SACJ;IACH,CAAC;IACD,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzB,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC7B,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxB,WAAW,C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ACzB,MAAM,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;oBACtC,MAAM,EAAE,GAAG;iBACZ,CAAC,CAAC;aACJ;SACF;QACD,KAAK,MAAM,GAAG,IAAI,MAAA,MAAA,GAAG,CAAC,OAAO,0CAAE,MAAM,EAAE,mCAAI,EAAE,EAAE;YAC7C,QAAQ,CAAC,GAAG,CAAC,CAAC;SACf;IACH,CAAC;IACD,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE;QACnD,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;KACzB;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/library-linter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.0-dev.1",
|
|
4
4
|
"author": "Microsoft Corporation",
|
|
5
5
|
"description": "TypeSpec library for linting another library.",
|
|
6
6
|
"homepage": "https://microsoft.github.io/typespec",
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"!dist/test/**"
|
|
43
43
|
],
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@typespec/compiler": "~0.44.0"
|
|
45
|
+
"@typespec/compiler": "~0.44.0 || >=0.45.0-dev <0.45.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/mocha": "~10.0.0",
|
|
49
49
|
"@types/node": "~18.11.9",
|
|
50
|
-
"@typespec/compiler": "~0.44.0",
|
|
51
|
-
"@typespec/eslint-config-typespec": "~0.7.0",
|
|
50
|
+
"@typespec/compiler": "~0.44.0 || >=0.45.0-dev <0.45.0",
|
|
51
|
+
"@typespec/eslint-config-typespec": "~0.7.0 || >=0.8.0-dev <0.8.0",
|
|
52
52
|
"eslint": "^8.36.0",
|
|
53
53
|
"mocha": "~10.2.0",
|
|
54
54
|
"mocha-junit-reporter": "~2.2.0",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"rimraf": "~5.0.0",
|
|
58
58
|
"typescript": "~5.0.2"
|
|
59
59
|
},
|
|
60
|
+
"dependencies": {},
|
|
60
61
|
"scripts": {
|
|
61
62
|
"clean": "rimraf ./dist ./temp",
|
|
62
63
|
"build": "tsc -p .",
|