mirror of
https://github.com/chenasraf/DefinitelyTyped-tools.git
synced 2026-05-18 01:49:03 +00:00
Format
This commit is contained in:
@@ -10,22 +10,25 @@ const rule = createRule({
|
||||
recommended: "error",
|
||||
},
|
||||
messages: {
|
||||
noDeclareCurrentPackage: `Instead of declaring a module with \`declare module "{{ text }}"\`, ` +
|
||||
noDeclareCurrentPackage:
|
||||
`Instead of declaring a module with \`declare module "{{ text }}"\`, ` +
|
||||
`write its contents in directly in {{ preferred }}.`,
|
||||
},
|
||||
schema: [],
|
||||
},
|
||||
create(context) {
|
||||
if (!context.getFilename().endsWith(".d.ts")) {
|
||||
return {}
|
||||
return {};
|
||||
}
|
||||
const parserServices = ESLintUtils.getParserServices(context);
|
||||
const packageName = getCommonDirectoryName(parserServices.program.getRootFileNames());
|
||||
return {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
TSModuleDeclaration(node) {
|
||||
if (node.id.type === AST_NODE_TYPES.Literal
|
||||
&& (node.id.value === packageName || node.id.value.startsWith(packageName + "/"))) {
|
||||
if (
|
||||
node.id.type === AST_NODE_TYPES.Literal &&
|
||||
(node.id.value === packageName || node.id.value.startsWith(packageName + "/"))
|
||||
) {
|
||||
const text = node.id.value;
|
||||
const preferred = text === packageName ? '"index.d.ts"' : `"${text}.d.ts" or "${text}/index.d.ts`;
|
||||
context.report({
|
||||
|
||||
@@ -8,7 +8,7 @@ const ruleTester = new ESLintUtils.RuleTester({
|
||||
ecmaVersion: 2018,
|
||||
tsconfigRootDir: __dirname,
|
||||
project: "./tsconfig.no-declare-current-package.json",
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
ruleTester.run("no-declare-current-package", noDeclareCurrentPackage, {
|
||||
@@ -29,7 +29,8 @@ ruleTester.run("no-declare-current-package", noDeclareCurrentPackage, {
|
||||
filename: "index.d.ts",
|
||||
code: `module "foo" { }
|
||||
module "foo/bar/baz" { }
|
||||
`}
|
||||
`,
|
||||
},
|
||||
],
|
||||
});
|
||||
// needed because you can only test one non-file.ts file per tsconfig
|
||||
@@ -40,11 +41,12 @@ const ruleTester2 = new ESLintUtils.RuleTester({
|
||||
ecmaVersion: 2018,
|
||||
tsconfigRootDir: __dirname,
|
||||
project: "./tsconfig.no-declare-current-package2.json",
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
ruleTester2.run("no-declare-current-package", noDeclareCurrentPackage, {
|
||||
invalid: [{
|
||||
invalid: [
|
||||
{
|
||||
filename: "deep/import.d.ts",
|
||||
code: `module "test/deep/import" { }`,
|
||||
errors: [
|
||||
|
||||
@@ -153,10 +153,7 @@ export function isArray(value: any): value is readonly {}[] {
|
||||
* @param array The array to map.
|
||||
* @param mapfn The callback used to map the result into one or more values.
|
||||
*/
|
||||
export function flatMap<T, U>(
|
||||
array: readonly T[] | undefined,
|
||||
mapfn: (x: T, i: number) => readonly U[]
|
||||
): readonly U[] {
|
||||
export function flatMap<T, U>(array: readonly T[] | undefined, mapfn: (x: T, i: number) => readonly U[]): readonly U[] {
|
||||
let result: U[] | undefined;
|
||||
if (array) {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user