@definitelytyped/eslint-plugin 0.0.197 → 0.0.198

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @definitelytyped/eslint-plugin
2
2
 
3
+ ## 0.0.198
4
+
5
+ ### Patch Changes
6
+
7
+ - 414ae487: Move npm-naming lint rule from tslint to eslint
8
+ - Updated dependencies [414ae487]
9
+ - @definitelytyped/dts-critic@0.0.192
10
+
3
11
  ## 0.0.197
4
12
 
5
13
  ### Patch Changes
@@ -135,7 +135,11 @@ exports.all = {
135
135
  warnOnUnsupportedTypeScriptVersion: false,
136
136
  },
137
137
  rules: {
138
- ...Object.fromEntries(Object.keys(rules_1.rules).map((name) => [`@definitelytyped/${name}`, "error"])),
138
+ ...Object.fromEntries(Object.keys(rules_1.rules)
139
+ // npm-naming is only enabled within dtslint.
140
+ // Leave it out of the preset so editors / he tests don't hit the network.
141
+ .filter((name) => name !== "npm-naming")
142
+ .map((name) => [`@definitelytyped/${name}`, "error"])),
139
143
  "unicode-bom": ["error", "never"],
140
144
  "@typescript-eslint/ban-ts-comment": [
141
145
  "error",
@@ -1 +1 @@
1
- {"version":3,"file":"all.js","sourceRoot":"","sources":["../../src/configs/all.ts"],"names":[],"mappings":";;;AAAA,oCAAiC;AAGpB,QAAA,GAAG,GAAsB;IACpC,OAAO,EAAE,CAAC,kBAAkB,EAAE,oBAAoB,EAAE,OAAO,CAAC;IAC5D,QAAQ,EAAE;QACR,KAAK,EAAE;YACL,iBAAiB,EAAE;gBACjB,QAAQ,EAAE,UAAU;gBACpB,SAAS,EAAE,WAAW;gBACtB,QAAQ,EAAE,UAAU;gBACpB,MAAM,EAAE,QAAQ;gBAChB,KAAK,EAAE,OAAO;gBACd,MAAM,EAAE,QAAQ;gBAChB,OAAO,EAAE,SAAS;aACnB;SACF;KACF;IACD,KAAK,EAAE;QACL,uBAAuB,EAAE;YACvB,OAA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E;4BACN,KAAK,EAAE,SAAS;4BAChB,KAAK,EAAE,KAAK;yBACb;qBACF;iBACF;gBACD,kDAAkD,EAAE,CAAC,OAAO,EAAE,EAAE,aAAa,EAAE,WAAW,EAAE,CAAC;gBAC7F,mCAAmC,EAAE,OAAO;gBAC5C,gDAAgD,EAAE,OAAO;gBACzD,yCAAyC,EAAE;oBACzC,OAAO;oBACP,EAAE,oBAAoB,EAAE,IAAI,EAAE,2BAA2B,EAAE,IAAI,EAAE;iBAClE;aACF;SACF;KACF;CACF,CAAC"}
1
+ {"version":3,"file":"all.js","sourceRoot":"","sources":["../../src/configs/all.ts"],"names":[],"mappings":";;;AAAA,oCAAiC;AAGpB,QAAA,GAAG,GAAsB;IACpC,OAAO,EAAE,CAAC,kBAAkB,EAAE,oBAAoB,EAAE,OAAO,CAAC;IAC5D,QAAQ,EAAE;QACR,KAAK,EAAE;YACL,iBAAiB,EAAE;gBACjB,QAAQ,EAAE,UAAU;gBACpB,SAAS,EAAE,WAAW;gBACtB,QAAQ,EAAE,UAAU;gBACpB,MAAM,EAAE,QAAQ;gBAChB,KAAK,EAAE,OAAO;gBACd,MAAM,EAAE,QAAQ;gBAChB,OAAO,EAAE,SAAS;aACnB;SACF;KACF;IACD,KAAK,EAAE;QACL,uBAAuB,EAAE;YACvB,OAAO;YACP;gBACE,kFAAkF;gBAClF,wEAAwE;gBACxE,WAAW,EAAE;oBACX,YAAY;oBACZ,MAAM;oBACN,KAAK;oBACL,QAAQ;oBACR,MAAM;oBACN,OAAO;oBACP,UAAU;oBACV,KAAK;oBACL,WAAW;oBACX,OAAO;oBACP,kBAAkB;oBAClB,kBAAkB;oBAClB,oBAAoB;oBACpB,YAAY;oBACZ,SAAS;oBACT,aAAa;oBACb,eAAe;oBACf,cAAc;oBACd,QAAQ;oBACR,KAAK;oBACL,eAAe;oBACf,cAAc;oBACd,QAAQ;oBACR,QAAQ;oBACR,cAAc;oBACd,SAAS;oBACT,OAAO;oBACP,OAAO;oBACP,OAAO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;KACF;CACF,CAAC"}
@@ -17,6 +17,7 @@ export declare const rules: {
17
17
  "no-single-declare-module": import("../util").RuleModule<never[], "oneModuleDeclaration">;
18
18
  "no-old-dt-header": import("../util").RuleModule<never[], "noOldDTHeader">;
19
19
  "no-import-of-dev-dependencies": import("../util").RuleModule<never[], "noImportOfDevDependencies" | "noReferenceOfDevDependencies">;
20
+ "npm-naming": import("../util").RuleModule<[import("./npm-naming/types").NpmNamingOptions], "error">;
20
21
  expect: import("../util").RuleModule<[{
21
22
  versionsToTest?: {
22
23
  readonly versionName: string;
@@ -19,6 +19,7 @@ const strictExportDeclareModifiers = require("./strict-export-declare-modifiers"
19
19
  const noSingleDeclareModule = require("./no-single-declare-module");
20
20
  const noOldDTHeader = require("./no-old-dt-header");
21
21
  const noImportOfDevDependencies = require("./no-import-of-dev-dependencies");
22
+ const npmNaming = require("./npm-naming");
22
23
  const expect = require("./expect");
23
24
  exports.rules = {
24
25
  "export-just-namespace": exportJustNamespace,
@@ -39,6 +40,7 @@ exports.rules = {
39
40
  "no-single-declare-module": noSingleDeclareModule,
40
41
  "no-old-dt-header": noOldDTHeader,
41
42
  "no-import-of-dev-dependencies": noImportOfDevDependencies,
43
+ "npm-naming": npmNaming,
42
44
  expect,
43
45
  };
44
46
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":";;;AAAA,+DAAgE;AAChE,6CAA8C;AAC9C,qDAAsD;AACtD,+CAAgD;AAChD,uDAAwD;AACxD,wEAAyE;AACzE,sFAAuF;AACvF,uEAAwE;AACxE,iDAAkD;AAClD,2EAA4E;AAC5E,mEAAoE;AACpE,qDAAsD;AACtD,mEAAoE;AACpE,4DAA6D;AAC7D,kFAAmF;AACnF,oEAAqE;AACrE,oDAAqD;AACrD,6EAA8E;AAC9E,mCAAoC;AAEvB,QAAA,KAAK,GAAG;IACnB,uBAAuB,EAAE,mBAAmB;IAC5C,cA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,qBAAqB;IAChD,qBAAqB,EAAE,kBAAkB;IACzC,iCAAiC,EAAE,4BAA4B;IAC/D,0BAA0B,EAAE,qBAAqB;IACjD,kBAAkB,EAAE,aAAa;IACjC,+BAA+B,EAAE,yBAAyB;IAC1D,YAAY,EAAE,SAAS;IACvB,MAAM;CACP,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { ExportErrorKind, Mode } from "@definitelytyped/dts-critic";
2
+ export type CodeRawOptionError = [ExportErrorKind, boolean];
3
+ export interface CodeRawOptions {
4
+ mode: Mode.Code;
5
+ errors: CodeRawOptionError[];
6
+ }
7
+ export interface NameOnlyRawOptions {
8
+ mode: Mode.NameOnly;
9
+ }
10
+ export type NpmNamingOptions = CodeRawOptions | NameOnlyRawOptions;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/rules/npm-naming/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import { NpmNamingOptions } from "./npm-naming/types";
2
+ declare const rule: import("../util").RuleModule<[NpmNamingOptions], "error">;
3
+ export = rule;
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ const dts_critic_1 = require("@definitelytyped/dts-critic");
3
+ const suggestions_1 = require("../suggestions");
4
+ const util_1 = require("../util");
5
+ function parseEnabledErrors(errors) {
6
+ const enabledChecks = [];
7
+ for (const tuple of errors) {
8
+ const error = (0, dts_critic_1.parseExportErrorKind)(tuple[0]);
9
+ if (error) {
10
+ enabledChecks.push([error, tuple[1]]);
11
+ }
12
+ }
13
+ return enabledChecks;
14
+ }
15
+ function parseRawOptions(rawOptions) {
16
+ switch (rawOptions.mode) {
17
+ case dts_critic_1.Mode.Code:
18
+ return { ...rawOptions, errors: new Map(parseEnabledErrors(rawOptions.errors)) };
19
+ case dts_critic_1.Mode.NameOnly:
20
+ return rawOptions;
21
+ }
22
+ }
23
+ const enabledSuggestions = [dts_critic_1.ErrorKind.JsPropertyNotInDts, dts_critic_1.ErrorKind.JsSignatureNotInDts];
24
+ function toOptionsWithSuggestions(options) {
25
+ if (options.mode === dts_critic_1.Mode.NameOnly) {
26
+ return options;
27
+ }
28
+ const optionsWithSuggestions = { mode: options.mode, errors: new Map(options.errors) };
29
+ for (const err of enabledSuggestions) {
30
+ optionsWithSuggestions.errors.set(err, true);
31
+ }
32
+ return optionsWithSuggestions;
33
+ }
34
+ function eslintDisableOption(error) {
35
+ switch (error) {
36
+ case dts_critic_1.ErrorKind.NoMatchingNpmPackage:
37
+ case dts_critic_1.ErrorKind.NoMatchingNpmVersion:
38
+ case dts_critic_1.ErrorKind.NonNpmHasMatchingPackage:
39
+ return `"off"`;
40
+ case dts_critic_1.ErrorKind.NoDefaultExport:
41
+ case dts_critic_1.ErrorKind.NeedsExportEquals:
42
+ case dts_critic_1.ErrorKind.JsSignatureNotInDts:
43
+ case dts_critic_1.ErrorKind.JsPropertyNotInDts:
44
+ case dts_critic_1.ErrorKind.DtsSignatureNotInJs:
45
+ case dts_critic_1.ErrorKind.DtsPropertyNotInJs:
46
+ return JSON.stringify(["error", { mode: dts_critic_1.Mode.Code, errors: [[error, false]] }]);
47
+ }
48
+ }
49
+ const rule = (0, util_1.createRule)({
50
+ name: "npm-naming",
51
+ defaultOptions: [
52
+ {
53
+ mode: dts_critic_1.Mode.NameOnly,
54
+ },
55
+ ],
56
+ meta: {
57
+ type: "problem",
58
+ docs: {
59
+ description: "Ensure that package name and DefinitelyTyped header match npm package info.",
60
+ },
61
+ messages: {
62
+ error: `{{ error }}
63
+ If you won't fix this error now or you think this error is wrong,
64
+ you can disable this check by adding the following options to your project's .eslintrc.json file under "rules":
65
+
66
+ "@definitelytyped/npm-naming": {{ option }}`,
67
+ },
68
+ schema: [
69
+ {
70
+ oneOf: [
71
+ {
72
+ additionalProperties: false,
73
+ properties: {
74
+ mode: {
75
+ type: "string",
76
+ enum: [dts_critic_1.Mode.NameOnly],
77
+ },
78
+ },
79
+ type: "object",
80
+ },
81
+ {
82
+ additionalProperties: false,
83
+ type: "object",
84
+ properties: {
85
+ mode: {
86
+ type: "string",
87
+ enum: [dts_critic_1.Mode.Code],
88
+ },
89
+ errors: {
90
+ type: "array",
91
+ items: {
92
+ type: "array",
93
+ items: [
94
+ {
95
+ description: "Name of the check.",
96
+ type: "string",
97
+ enum: [dts_critic_1.ErrorKind.NeedsExportEquals, dts_critic_1.ErrorKind.NoDefaultExport],
98
+ },
99
+ {
100
+ description: "Whether the check is enabled or disabled.",
101
+ type: "boolean",
102
+ },
103
+ ],
104
+ minItems: 2,
105
+ maxItems: 2,
106
+ },
107
+ },
108
+ },
109
+ },
110
+ ],
111
+ },
112
+ ],
113
+ },
114
+ create(context, [rawOptions]) {
115
+ if (!(0, util_1.isMainFile)(context.filename, /*allowNested*/ false)) {
116
+ return {};
117
+ }
118
+ const options = parseRawOptions(rawOptions);
119
+ const optionsWithSuggestions = toOptionsWithSuggestions(options);
120
+ const diagnostics = (0, dts_critic_1.dtsCritic)(context.filename, /* sourcePath */ undefined, optionsWithSuggestions);
121
+ const errors = filterErrors(diagnostics);
122
+ for (const error of errors) {
123
+ switch (error.kind) {
124
+ case dts_critic_1.ErrorKind.NoMatchingNpmPackage:
125
+ case dts_critic_1.ErrorKind.NoMatchingNpmVersion:
126
+ case dts_critic_1.ErrorKind.NonNpmHasMatchingPackage:
127
+ case dts_critic_1.ErrorKind.DtsPropertyNotInJs:
128
+ case dts_critic_1.ErrorKind.DtsSignatureNotInJs:
129
+ case dts_critic_1.ErrorKind.JsPropertyNotInDts:
130
+ case dts_critic_1.ErrorKind.JsSignatureNotInDts:
131
+ case dts_critic_1.ErrorKind.NeedsExportEquals:
132
+ case dts_critic_1.ErrorKind.NoDefaultExport:
133
+ context.report({
134
+ data: {
135
+ error: error.message,
136
+ option: eslintDisableOption(error.kind),
137
+ },
138
+ loc: error.position
139
+ ? {
140
+ start: context.sourceCode.getLocFromIndex(error.position.start),
141
+ end: context.sourceCode.getLocFromIndex(error.position.start + error.position.length),
142
+ }
143
+ : {
144
+ end: {
145
+ line: 2,
146
+ column: 0,
147
+ },
148
+ start: {
149
+ line: 1,
150
+ column: 0,
151
+ },
152
+ },
153
+ messageId: "error",
154
+ });
155
+ break;
156
+ }
157
+ }
158
+ return {};
159
+ function filterErrors(diagnostics) {
160
+ const errors = [];
161
+ diagnostics.forEach((diagnostic) => {
162
+ var _a, _b;
163
+ if (isSuggestion(diagnostic)) {
164
+ (0, suggestions_1.addSuggestion)(context.filename, "npm-naming", diagnostic.message, (_a = diagnostic.position) === null || _a === void 0 ? void 0 : _a.start, (_b = diagnostic.position) === null || _b === void 0 ? void 0 : _b.length);
165
+ }
166
+ else {
167
+ errors.push(diagnostic);
168
+ }
169
+ });
170
+ return errors;
171
+ }
172
+ function isSuggestion(diagnostic) {
173
+ return (options.mode === dts_critic_1.Mode.Code &&
174
+ enabledSuggestions.includes(diagnostic.kind) &&
175
+ !options.errors.get(diagnostic.kind));
176
+ }
177
+ },
178
+ });
179
+ module.exports = rule;
180
+ //# sourceMappingURL=npm-naming.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"npm-naming.js","sourceRoot":"","sources":["../../src/rules/npm-naming.ts"],"names":[],"mappings":";AAAA,4DAQqC;AAErC,gDAA+C;AAC/C,kCAAiD;AAGjD,SAAS,kBAAkB,CAAC,MAA4B;IACtD,MAAM,aAAa,GAAiC,EAAE,CAAC;IACvD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QAC1B,MAAM,KAAK,GAAG,IAAA,iCAAoB,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7C,IAAI,KAAK,EAAE;YACT,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACvC;KACF;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,SAAS,eAAe,CAAC,U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+ * A rule should call this function to provide a suggestion instead of a lint failure.
3
+ */
4
+ export declare function addSuggestion(fileName: string, ruleName: string, message: string, start?: number, width?: number): void;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addSuggestion = void 0;
4
+ const fs = require("fs");
5
+ const os = require("os");
6
+ const path = require("path");
7
+ const suggestionsDir = path.join(os.homedir(), ".dts", "suggestions");
8
+ // Packages for which suggestions were already added in this run of dtslint.
9
+ const existingPackages = new Set();
10
+ /**
11
+ * A rule should call this function to provide a suggestion instead of a lint failure.
12
+ */
13
+ function addSuggestion(fileName, ruleName, message, start, width) {
14
+ const suggestion = {
15
+ fileName,
16
+ ruleName,
17
+ message,
18
+ start,
19
+ width,
20
+ };
21
+ const packageName = dtPackageName(fileName);
22
+ if (!packageName) {
23
+ return;
24
+ }
25
+ let flag = "a";
26
+ if (!existingPackages.has(packageName)) {
27
+ flag = "w";
28
+ existingPackages.add(packageName);
29
+ }
30
+ try {
31
+ if (!fs.existsSync(suggestionsDir)) {
32
+ fs.mkdirSync(suggestionsDir, { recursive: true });
33
+ }
34
+ fs.writeFileSync(path.join(suggestionsDir, packageName + ".txt"), flag === "a" ? "\n" + formatSuggestion(suggestion) : formatSuggestion(suggestion), { flag, encoding: "utf8" });
35
+ }
36
+ catch (e) {
37
+ console.log(`Could not write suggestions for package ${packageName}. ${e.message || ""}`);
38
+ }
39
+ }
40
+ exports.addSuggestion = addSuggestion;
41
+ const dtPath = path.join("DefinitelyTyped", "types");
42
+ function dtPackageName(filePath) {
43
+ const dtIndex = filePath.indexOf(dtPath);
44
+ if (dtIndex === -1) {
45
+ return undefined;
46
+ }
47
+ const basePath = filePath.substr(dtIndex + dtPath.length);
48
+ const dirs = basePath.split(path.sep).filter((dir) => dir !== "");
49
+ if (dirs.length === 0) {
50
+ return undefined;
51
+ }
52
+ const packageName = dirs[0];
53
+ // Check if this is an old version of a package.
54
+ if (dirs.length > 1 && /^v\d+(\.\d+)?$/.test(dirs[1])) {
55
+ return packageName + dirs[1];
56
+ }
57
+ return packageName;
58
+ }
59
+ function formatSuggestion(suggestion) {
60
+ return JSON.stringify(suggestion, /*replacer*/ undefined, 0);
61
+ }
62
+ //# sourceMappingURL=suggestions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suggestions.js","sourceRoot":"","sources":["../src/suggestions.ts"],"names":[],"mappings":";;;AAAA,yBAA0B;AAC1B,yBAA0B;AAC1B,6BAA8B;AAE9B,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;AAUtE,4EAA4E;AAC5E,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;AAEnC;;GAEG;AACH,SAAgB,aAAa,CAAC,QAAgB,EAAE,QAAgB,EAAE,OAAe,EAAE,KAAc,EAAE,KAAc;IAC/G,MAAM,UAAU,GAAe;QAC7B,QAAQ;QACR,QAAQ;QACR,OAAO;QACP,KAAK;QACL,KAAK;KACN,CAAC;IAEF,MAAM,WAAW,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC5C,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO;KACR;IACD,IAAI,IAAI,GAAG,GAAG,CAAC;IACf,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;QACtC,IAAI,GAAG,GAAG,CAAC;QACX,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;KACnC;IACD,IAAI;QACF,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE;YAClC,EAAE,CAAC,SAAS,CAAC,cAAc,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;SACnD;QACD,EAAE,CAAC,aAAa,CACd,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,WAAW,GAAG,MAAM,CAAC,EAC/C,IAAI,KAAK,GAAG,CAA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AAC,UAAU,EAAE,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;AAC/D,CAAC"}
package/dist/util.d.ts CHANGED
@@ -20,3 +20,4 @@ export interface PackageJSON {
20
20
  }
21
21
  export declare function findTypesPackage(file: string): TypesPackageInfo | undefined;
22
22
  export declare function getImportSource(node: TSESTree.ImportDeclaration | TSESTree.TSImportEqualsDeclaration): TSESTree.StringLiteral | undefined;
23
+ export declare function isMainFile(fileName: string, allowNested: boolean): boolean;
package/dist/util.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getImportSource = exports.findTypesPackage = exports.findUp = exports.commentsMatching = exports.getTypesPackageForDeclarationFile = exports.createRule = void 0;
6
+ exports.isMainFile = exports.getImportSource = exports.findTypesPackage = exports.findUp = exports.commentsMatching = exports.getTypesPackageForDeclarationFile = exports.createRule = void 0;
7
7
  const utils_1 = require("@definitelytyped/utils");
8
8
  const utils_2 = require("@typescript-eslint/utils");
9
9
  const path_1 = __importDefault(require("path"));
@@ -79,4 +79,22 @@ function getImportSource(node) {
79
79
  return undefined;
80
80
  }
81
81
  exports.getImportSource = getImportSource;
82
+ function isMainFile(fileName, allowNested) {
83
+ // Linter may be run with cwd of the package. We want `index.d.ts` but not `submodule/index.d.ts` to match.
84
+ if (fileName === "index.d.ts") {
85
+ return true;
86
+ }
87
+ if (path_1.default.basename(fileName) !== "index.d.ts") {
88
+ return false;
89
+ }
90
+ let parent = path_1.default.dirname(fileName);
91
+ // May be a directory for an older version, e.g. `v0`.
92
+ // Note a types redirect `foo/ts3.1` should not have its own header.
93
+ if (allowNested && /^v(0\.)?\d+$/.test(path_1.default.basename(parent))) {
94
+ parent = path_1.default.dirname(parent);
95
+ }
96
+ // Allow "types/foo/index.d.ts", not "types/foo/utils/index.d.ts"
97
+ return path_1.default.basename(path_1.default.dirname(parent)) === "types";
98
+ }
99
+ exports.isMainFile = isMainFile;
82
100
  //# sourceMappingURL=util.js.map
package/dist/util.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAuF;AACvF,oDAA2E;AAC3E,gDAAwB;AACxB,4CAAoB;AASP,QAAA,UAAU,GAEkB,mBAAW,CAAC,WAAW,CAC9D,CAAC,IAAI,EAAE,EAAE,CACP,oGAAoG,IAAI,KAAK,CAChH,CAAC;AAEF,SAAgB,iCAAiC,CAAC,IAAY;;IAC5D,IAAI,CAAC,IAAA,yBAAiB,EAAC,IAAI,CAAC,EAAE;QAC5B,OAAO,SAAS,CAAC;KAClB;IACD,OAAO,MAAA,gBAAgB,CAAC,IAAI,CAAC,0CAAE,QAAQ,CAAC;AAC1C,CAAC;AALD,8EAKC;AAED,SAAgB,gBAAgB,CAC9B,UAAyC,EACzC,KAAa,EACb,CAA+C;IAE/C,KAAK,MAAM,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE;QAC7C,MAAM,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,CAAC;YAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;KACzB;AACH,CAAC;AATD,4CASC;AAED,SAAgB,MAAM,CAAe,CAAS,EAAE,EAAgC;IAC9E,CAAC,GAAG,cAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,IAAI,GAAG,cAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEhC,OAAO,IAAI,EAAE;QACX,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QAChB,IAAI,CAAC,KAAK,SAAS,EAAE;YACnB,OAAO,CAAC,CAAC;SACV;QACD,IAAI,CAAC,KAAK,IAAI,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AAgB,eAAe,CAC7B,IAAqE;IAErE,IAAI,IAAI,CAAC,IAAI,KAAK,mBAAmB,EAAE;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC;KACpB;IAED,IACE,IAAI,CAAC,eAAe,CAAC,IAAI,KAAK,2BAA2B;QACzD,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,IAAI,KAAK,SAAS;QAClD,OAAO,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,KAAK,KAAK,QAAQ,EACzD;QACA,OAAO,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC;KACxC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAhBD,0CAgBC;AAED,SAAgB,UAAU,CAAC,QAAgB,EAAE,WAAoB;IAC/D,2GAA2G;IAC3G,IAAI,QAAQ,KAAK,YAAY,EAAE;QAC7B,OAAO,IAAI,CAAC;KACb;IAED,IAAI,cAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,YAAY,EAAE;QAC5C,OAAO,KAAK,CAAC;KACd;IAED,IAAI,MAAM,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpC,sDAAsD;IACtD,oEAAoE;IACpE,IAAI,WAAW,IAAI,cAAc,CAAC,IAAI,CAAC,cAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE;QAC7D,MAAM,GAAG,cAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;KAC/B;IAED,iEAAiE;IACjE,OAAO,cAAI,CAAC,QAAQ,CAAC,cAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,OAAO,CAAC;AACzD,CAAC;AAnBD,gCAmBC"}
@@ -0,0 +1,137 @@
1
+ # npm-naming
2
+
3
+ (This rule is specific to DefinitelyTyped.)
4
+
5
+ ## Name checks
6
+ In 'name-only' mode, checks that the name of the type package matches a source package on npm.
7
+
8
+ ---
9
+
10
+ **Bad**:
11
+
12
+ ```ts
13
+ // Type definitions for browser-only-package 1.2
14
+ ```
15
+
16
+ * If the package is really browser-only, you have to mark it with "non-npm package".
17
+ * If the package actually has a matching npm package, you must use that name.
18
+
19
+ **Good**:
20
+
21
+ ```ts
22
+ // Type definitions for non-npm package browser-only-package 1.2
23
+ ```
24
+
25
+ ---
26
+
27
+ **Bad**:
28
+
29
+ ```ts
30
+ // Type definitions for some-package 101.1
31
+ ```
32
+
33
+ * The version number in the header must actually exist on npm for the source package.
34
+
35
+ **Good**:
36
+
37
+ ```ts
38
+ // Type definitions for some-package 10.1
39
+ ```
40
+
41
+ ## Code checks
42
+
43
+ In 'code' mode, in addition to the name checks, this rule also checks that the source JavaScript code matches the declaration file for npm packages.
44
+
45
+ ---
46
+
47
+ **Bad**:
48
+
49
+ `foo/index.d.ts`:
50
+
51
+ ```ts
52
+ declare function f(): void;
53
+ export default f;
54
+ ```
55
+
56
+ `foo/index.js`:
57
+
58
+ ```js
59
+ module.exports = function () {
60
+ };
61
+ ```
62
+
63
+ * A CommonJs module.exports assignment is not really an export default, and the d.ts should use the [`export =`](https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require) syntax.
64
+ * `export default` can only be used to export a CommonJs `module.exports =` when you have `esModuleInterop` turned on, which not everybody does.
65
+
66
+ **Good**:
67
+
68
+ `foo/index.d.ts`:
69
+
70
+ ```ts
71
+ declare function f(): void;
72
+ export = f;
73
+ ```
74
+
75
+ ---
76
+
77
+ **Bad**:
78
+
79
+ `foo/index.d.ts`:
80
+
81
+ ```ts
82
+ export class C {}
83
+ ```
84
+
85
+ `foo/index.js`:
86
+
87
+ ```js
88
+ module.exports = class C {}
89
+ ```
90
+
91
+ * The CommonJs module is a class, which means it can be constructed, like this:
92
+ ```js
93
+ var C = require('foo');
94
+ var x = new C();
95
+ ```
96
+ However, the way `class C` is exported in the d.ts file (using an export declaration) means it can only be used like this:
97
+ ```ts
98
+ var foo = require('foo');
99
+ var x = new foo.C();
100
+ ```
101
+
102
+ * The d.ts should use [`export =`](https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require)
103
+ syntax to match the CommonJs module behavior.
104
+
105
+ **Good**:
106
+
107
+ `foo/index.d.ts`:
108
+
109
+ ```ts
110
+ declare class C {}
111
+ export = C;
112
+ ```
113
+
114
+ * If you need to use `export =` syntax as in the example above, and the source JavaScript also exports some properties,
115
+ you might need to use [*declaration merging*](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#merging-namespaces-with-classes-functions-and-enums) in your d.ts. Example:
116
+
117
+ **JavaScript**:
118
+
119
+ `foo/index.js`:
120
+
121
+ ```js
122
+ function foo() {};
123
+ foo.bar = "Exported property";
124
+ module.exports = foo; // module.exports is a function, but it also has a property called `bar`
125
+ ```
126
+
127
+ **Declaration**:
128
+
129
+ `foo/index.d.ts`:
130
+
131
+ ```ts
132
+ declare function foo(): void;
133
+ declare namespace foo {
134
+ var bar: string;
135
+ }
136
+ export = foo;
137
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@definitelytyped/eslint-plugin",
3
- "version": "0.0.197",
3
+ "version": "0.0.198",
4
4
  "description": "ESLint rules for DefinitelyTyped",
5
5
  "main": "./dist/index.js",
6
6
  "publishConfig": {
@@ -20,6 +20,7 @@
20
20
  "dependencies": {
21
21
  "@typescript-eslint/types": "^6.11.0",
22
22
  "@typescript-eslint/utils": "^6.11.0",
23
+ "@definitelytyped/dts-critic": "0.0.192",
23
24
  "@definitelytyped/utils": "0.0.188"
24
25
  },
25
26
  "peerDependencies": {
@@ -31,6 +32,7 @@
31
32
  },
32
33
  "devDependencies": {
33
34
  "@definitelytyped/eslint-plugin": "link:./",
35
+ "@typescript-eslint/rule-tester": "^6.11.0",
34
36
  "@types/eslint": "^8.44.7",
35
37
  "glob": "^10.3.10",
36
38
  "jest-file-snapshot": "^0.5.0",
@@ -135,7 +135,13 @@ export const all: Linter.BaseConfig = {
135
135
  warnOnUnsupportedTypeScriptVersion: false,
136
136
  },
137
137
  rules: {
138
- ...Object.fromEntries(Object.keys(rules).map((name) => [`@definitelytyped/${name}`, "error"])),
138
+ ...Object.fromEntries(
139
+ Object.keys(rules)
140
+ // npm-naming is only enabled within dtslint.
141
+ // Leave it out of the preset so editors / he tests don't hit the network.
142
+ .filter((name) => name !== "npm-naming")
143
+ .map((name) => [`@definitelytyped/${name}`, "error"]),
144
+ ),
139
145
  "unicode-bom": ["error", "never"],
140
146
  "@typescript-eslint/ban-ts-comment": [
141
147
  "error",
@@ -16,6 +16,7 @@ import strictExportDeclareModifiers = require("./strict-export-declare-modifiers
16
16
  import noSingleDeclareModule = require("./no-single-declare-module");
17
17
  import noOldDTHeader = require("./no-old-dt-header");
18
18
  import noImportOfDevDependencies = require("./no-import-of-dev-dependencies");
19
+ import npmNaming = require("./npm-naming");
19
20
  import expect = require("./expect");
20
21
 
21
22
  export const rules = {
@@ -37,5 +38,6 @@ export const rules = {
37
38
  "no-single-declare-module": noSingleDeclareModule,
38
39
  "no-old-dt-header": noOldDTHeader,
39
40
  "no-import-of-dev-dependencies": noImportOfDevDependencies,
41
+ "npm-naming": npmNaming,
40
42
  expect,
41
43
  };
@@ -0,0 +1,14 @@
1
+ import { ExportErrorKind, Mode } from "@definitelytyped/dts-critic";
2
+
3
+ export type CodeRawOptionError = [ExportErrorKind, boolean];
4
+
5
+ export interface CodeRawOptions {
6
+ mode: Mode.Code;
7
+ errors: CodeRawOptionError[];
8
+ }
9
+
10
+ export interface NameOnlyRawOptions {
11
+ mode: Mode.NameOnly;
12
+ }
13
+
14
+ export type NpmNamingOptions = CodeRawOptions | NameOnlyRawOptions;