Skip to content

Commit 5c3f560

Browse files
committed
Update to TypeScript 4, and bump linter dependencies
1 parent 0543b66 commit 5c3f560

29 files changed

Lines changed: 955 additions & 9886 deletions

.eslintrc.js

Lines changed: 12 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -5,142 +5,20 @@ module.exports = {
55
tsconfigRootDir: __dirname, // this is the reason this is a .js file
66
project: ['./tsconfig.eslint.json'],
77
},
8-
plugins: [
9-
'eslint-plugin-tsdoc',
10-
'eslint-plugin-import',
11-
'eslint-plugin-jest',
12-
'eslint-plugin-unused-imports'
13-
],
148
extends: [
15-
'es/node',
16-
'plugin:import/errors',
17-
'plugin:import/warnings',
18-
'plugin:import/typescript'
9+
'@rubensworks'
1910
],
20-
settings: {
21-
'import/parsers': {
22-
'@typescript-eslint/parser': ['.ts', '.tsx']
23-
},
24-
'import/resolver': {
25-
'typescript': {
26-
'alwaysTryTypes': true // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/rdf-js`
27-
},
28-
}
29-
},
30-
globals: {
31-
window: false,
32-
fetch: false,
33-
Headers: false,
34-
Request: false,
35-
XMLHttpRequest: false,
36-
},
3711
rules: {
38-
// Default
39-
'class-methods-use-this': 'off', // Conflicts with functions from interfaces that sometimes don't require `this`
40-
'comma-dangle': ['error', 'always-multiline'],
41-
'dot-location': ['error', 'property'],
42-
'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
43-
'no-underscore-dangle': 'off', // Conflicts with external libraries
44-
'padding-line-between-statements': 'off',
45-
'no-param-reassign': 'off',
46-
'func-style': 'off',
47-
'new-cap': 'off',
48-
'lines-around-comment': ['error', {
49-
beforeBlockComment: false,
50-
afterBlockComment: false,
51-
beforeLineComment: false,
52-
afterLineComment: false,
53-
}],
54-
'no-multi-assign': 'off',
55-
'no-plusplus': 'off',
56-
'guard-for-in': 'off',
57-
'sort-imports': 'off', // Disabled in favor of eslint-plugin-import
58-
'prefer-named-capture-group': 'off',
59-
'max-len': ['error', {
60-
code: 120,
61-
ignoreTemplateLiterals: true,
62-
}],
63-
'unicorn/consistent-function-scoping': 'off',
64-
'no-warning-comments': 'off',
65-
'no-mixed-operators': 'off',
66-
'prefer-destructuring': 'off',
67-
'default-case': 'off', // TSC already takes care of these checks
68-
'no-loop-func': 'off',
69-
'unicorn/no-fn-reference-in-iterator': 'off',
70-
'extended/consistent-err-names': 'off',
71-
'unicorn/prefer-replace-all': 'off',
72-
73-
// TS
74-
'@typescript-eslint/array-type': ['error', { default: 'array' }],
75-
'@typescript-eslint/generic-type-naming': 'off',
76-
'@typescript-eslint/no-empty-interface': 'off',
77-
'@typescript-eslint/no-unnecessary-condition': 'off', // Problems with optional parameters
78-
'@typescript-eslint/space-before-function-paren': ['error', 'never'],
79-
'@typescript-eslint/promise-function-async': 'off',
80-
'@typescript-eslint/consistent-type-assertions': ['error', { assertionStyle: 'angle-bracket' }],
81-
'@typescript-eslint/member-naming': 'off',
82-
'@typescript-eslint/naming-convention': 'error',
83-
'@typescript-eslint/no-dynamic-delete': 'off',
84-
'@typescript-eslint/explicit-function-return-type': 'off',
85-
'@typescript-eslint/no-use-before-define': 'off',
86-
'@typescript-eslint/prefer-nullish-coalescing': 'off',
87-
88-
// Import
89-
'import/order': ['error', {
90-
alphabetize: {
91-
order: 'asc',
92-
caseInsensitive: true
12+
'@typescript-eslint/naming-convention': [
13+
'error',
14+
{
15+
'selector': 'interface',
16+
'format': ['PascalCase'],
17+
'custom': {
18+
'regex': '^[A-Z]',
19+
'match': true
20+
}
9321
}
94-
}],
95-
'import/no-unused-modules': 'off',
96-
'unused-imports/no-unused-imports-ts': 'error',
97-
98-
// TODO: Try to re-enable the following rules in the future
99-
'tsdoc/syntax': 'off',
100-
},
101-
overrides: [
102-
{
103-
// Specific rules for bin files
104-
files: ['**/bin/*.ts'],
105-
rules: {
106-
'no-process-env': 'off',
107-
}
108-
},
109-
{
110-
// Specific rules for test files
111-
files: ['test/**/*.ts'],
112-
env: {
113-
'jest/globals': true,
114-
},
115-
globals: {
116-
'spyOn': false,
117-
},
118-
rules: {
119-
'mocha/no-synchronous-tests': 'off',
120-
'mocha/valid-test-description': 'off',
121-
'mocha/no-sibling-hooks': 'off',
122-
'mocha/no-top-level-hooks': 'off',
123-
124-
'max-statements-per-line': 'off',
125-
'id-length': 'off',
126-
'arrow-body-style': 'off',
127-
'line-comment-position': 'off',
128-
'no-inline-comments': 'off',
129-
'unicorn/filename-case': 'off',
130-
'no-new': 'off',
131-
'unicorn/no-nested-ternary': 'off',
132-
'no-return-assign': 'off',
133-
'no-useless-call': 'off',
134-
'no-sync': 'off',
135-
136-
'@typescript-eslint/brace-style': 'off',
137-
'@typescript-eslint/ban-ts-comment': 'off',
138-
'@typescript-eslint/ban-ts-ignore': 'off',
139-
'@typescript-eslint/explicit-function-return-type': 'off',
140-
'@typescript-eslint/unbound-method': 'off',
141-
'@typescript-eslint/no-extra-parens': 'off',
142-
'@typescript-eslint/restrict-plus-operands': 'off'
143-
}
144-
}
145-
],
22+
],
23+
}
14624
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as minimist from 'minimist';
33
import { Generator } from '../lib/generate/Generator';
44
import { ResolutionContext } from '../lib/resolution/ResolutionContext';
55

6-
function showHelp() {
6+
function showHelp(): void {
77
process.stderr.write(`Generates components files for TypeScript files in a package
88
Usage:
99
componentsjs-generator

lib/generate/Generator.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { ClassLoader } from '../parse/ClassLoader';
55
import { ConstructorLoader } from '../parse/ConstructorLoader';
66
import { PackageMetadataLoader } from '../parse/PackageMetadataLoader';
77
import { ParameterResolver } from '../parse/ParameterResolver';
8-
import { ResolutionContext } from '../resolution/ResolutionContext';
9-
import { ComponentConstructor, PathDestinationDefinition } from '../serialize/ComponentConstructor';
8+
import type { ResolutionContext } from '../resolution/ResolutionContext';
9+
import type { PathDestinationDefinition } from '../serialize/ComponentConstructor';
10+
import { ComponentConstructor } from '../serialize/ComponentConstructor';
1011
import { ComponentSerializer } from '../serialize/ComponentSerializer';
1112
import { ContextConstructor } from '../serialize/ContextConstructor';
1213

lib/parse/ClassFinder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ClassIndex, ClassReference } from './ClassIndex';
2-
import { ClassLoader } from './ClassLoader';
1+
import type { ClassIndex, ClassReference } from './ClassIndex';
2+
import type { ClassLoader } from './ClassLoader';
33

44
/**
55
* Load the names and locations of all available classes that are exported by a package.

lib/parse/ClassIndex.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import { ClassDeclaration, TSInterfaceDeclaration, TypeNode } from '@typescript-eslint/types/dist/ts-estree';
2-
import { AST, TSESTreeOptions } from '@typescript-eslint/typescript-estree';
1+
import type { ClassDeclaration, TSInterfaceDeclaration, TypeNode } from '@typescript-eslint/types/dist/ts-estree';
2+
import type { AST, TSESTreeOptions } from '@typescript-eslint/typescript-estree';
33

44
/**
55
* A collection of classes, with exported name as key.
66
*/
7-
export interface ClassIndex<T> {
8-
// The exported name of the class, as visible by externals importing it.
9-
[className: string]: T;
10-
}
7+
export type ClassIndex<T> = Record<string, T>;
118

129
/**
1310
* The name and location of a class.
@@ -50,9 +47,7 @@ export interface ClassLoaded extends ClassReference {
5047
/**
5148
* A hash of generic type name to its properties.
5249
*/
53-
export interface GenericTypes {
54-
[name: string]: { type?: TypeNode };
55-
}
50+
export type GenericTypes = Record<string, { type?: TypeNode }>;
5651

5752
/**
5853
* A loaded interface with a full interface declaration.

lib/parse/ClassIndexer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/**
22
* Creates an index of classes in a certain package.
33
*/
4-
import { ClassFinder } from './ClassFinder';
5-
import { ClassIndex, ClassLoaded, ClassReference } from './ClassIndex';
6-
import { ClassLoader } from './ClassLoader';
4+
import type { ClassFinder } from './ClassFinder';
5+
import type { ClassIndex, ClassLoaded, ClassReference } from './ClassIndex';
6+
import type { ClassLoader } from './ClassLoader';
77

88
export class ClassIndexer {
99
/**
1010
* Errors that do not require an import, and are assumed to be known globally.
1111
*/
12-
private static readonly SUPERCLASS_BLACKLIST: {[name: string]: boolean} = {
12+
private static readonly SUPERCLASS_BLACKLIST: Record<string, boolean> = {
1313
Error: true,
1414
};
1515

lib/parse/ClassLoader.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as Path from 'path';
2-
import { ClassDeclaration, TSInterfaceDeclaration } from '@typescript-eslint/types/dist/ts-estree';
3-
import { AST, AST_NODE_TYPES, TSESTreeOptions } from '@typescript-eslint/typescript-estree';
4-
import { ResolutionContext } from '../resolution/ResolutionContext';
5-
import { ClassLoaded, ClassReference, ClassReferenceLoaded, GenericTypes, InterfaceLoaded } from './ClassIndex';
2+
import type { ClassDeclaration, TSInterfaceDeclaration } from '@typescript-eslint/types/dist/ts-estree';
3+
import type { AST, TSESTreeOptions } from '@typescript-eslint/typescript-estree';
4+
import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
5+
import type { ResolutionContext } from '../resolution/ResolutionContext';
6+
import type { ClassLoaded, ClassReference, ClassReferenceLoaded, GenericTypes, InterfaceLoaded } from './ClassIndex';
67
import { CommentLoader } from './CommentLoader';
78

89
/**
@@ -143,7 +144,7 @@ export class ClassLoader {
143144
try {
144145
return await this.loadClassDeclaration({ localName: classReference.localName, fileName: subFile },
145146
considerInterfaces);
146-
} catch (error) {
147+
} catch {
147148
// Ignore class not found errors
148149
}
149150
}
@@ -193,14 +194,14 @@ export class ClassLoader {
193194
* @param ast The parsed file.
194195
*/
195196
public getClassElements(fileName: string, ast: AST<TSESTreeOptions>): ClassElements {
196-
const exportedClasses: { [exportedName: string]: ClassDeclaration } = {};
197-
const exportedInterfaces: { [exportedName: string]: TSInterfaceDeclaration } = {};
198-
const exportedImportedElements: { [exportedName: string]: { localName: string; fileName: string } } = {};
197+
const exportedClasses: Record<string, ClassDeclaration> = {};
198+
const exportedInterfaces: Record<string, TSInterfaceDeclaration> = {};
199+
const exportedImportedElements: Record<string, { localName: string; fileName: string }> = {};
199200
const exportedImportedAll: string[] = [];
200-
const exportedUnknowns: { [exportedName: string]: string } = {};
201-
const declaredClasses: { [localName: string]: ClassDeclaration } = {};
202-
const declaredInterfaces: { [localName: string]: TSInterfaceDeclaration } = {};
203-
const importedElements: { [exportedName: string]: { localName: string; fileName: string } } = {};
201+
const exportedUnknowns: Record<string, string> = {};
202+
const declaredClasses: Record<string, ClassDeclaration> = {};
203+
const declaredInterfaces: Record<string, TSInterfaceDeclaration> = {};
204+
const importedElements: Record<string, { localName: string; fileName: string }> = {};
204205

205206
for (const statement of ast.body) {
206207
if (statement.type === AST_NODE_TYPES.ExportNamedDeclaration) {
@@ -281,19 +282,19 @@ export interface ClassLoaderArgs {
281282
*/
282283
export interface ClassElements {
283284
// Classes that have been declared in a file via `export class A`
284-
exportedClasses: {[exportedName: string]: ClassDeclaration};
285+
exportedClasses: Record<string, ClassDeclaration>;
285286
// Interfaces that have been declared in a file via `export interface A`
286-
exportedInterfaces: {[exportedName: string]: TSInterfaceDeclaration};
287+
exportedInterfaces: Record<string, TSInterfaceDeclaration>;
287288
// Elements that have been exported via `export { A as B } from "b"`
288-
exportedImportedElements: { [exportedName: string]: { localName: string; fileName: string } };
289+
exportedImportedElements: Record<string, { localName: string; fileName: string }>;
289290
// Exports via `export * from "b"`
290291
exportedImportedAll: string[];
291292
// Things that have been exported via `export {A as B}`, where the target is not known
292-
exportedUnknowns: { [exportedName: string]: string };
293+
exportedUnknowns: Record<string, string>;
293294
// Classes that have been declared in a file via `declare class A`
294-
declaredClasses: {[localName: string]: ClassDeclaration};
295+
declaredClasses: Record<string, ClassDeclaration>;
295296
// Interfaces that have been declared in a file via `declare interface A`
296-
declaredInterfaces: {[localName: string]: TSInterfaceDeclaration};
297+
declaredInterfaces: Record<string, TSInterfaceDeclaration>;
297298
// Elements that are imported from elsewhere via `import {A} from ''`
298-
importedElements: {[exportedName: string]: { localName: string; fileName: string }};
299+
importedElements: Record<string, { localName: string; fileName: string }>;
299300
}

lib/parse/CommentLoader.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { ClassDeclaration, TSInterfaceDeclaration,
1+
import type { ClassDeclaration, TSInterfaceDeclaration,
22
MethodDefinition, TSPropertySignature, TSIndexSignature, BaseNode } from '@typescript-eslint/types/dist/ts-estree';
33
import * as commentParse from 'comment-parser';
4-
import { ClassReference, ClassReferenceLoaded } from './ClassIndex';
5-
import { ParameterRangeUnresolved } from './ParameterLoader';
4+
import type { ClassReference, ClassReferenceLoaded } from './ClassIndex';
5+
import type { ParameterRangeUnresolved } from './ParameterLoader';
66

77
/**
88
* Loads comments from fields in a given class.
@@ -141,9 +141,7 @@ export interface CommentLoaderArgs {
141141
classLoaded: ClassReferenceLoaded;
142142
}
143143

144-
export interface ConstructorCommentData {
145-
[fieldName: string]: CommentData;
146-
}
144+
export type ConstructorCommentData = Record<string, CommentData>;
147145

148146
export interface CommentData {
149147
/**
@@ -165,5 +163,5 @@ export interface CommentData {
165163
/**
166164
* Parameters that were defined in this comment.
167165
*/
168-
params?: {[paramName: string]: string};
166+
params?: Record<string, string>;
169167
}

lib/parse/ConstructorLoader.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { ClassDeclaration, MethodDefinition } from '@typescript-eslint/types/dist/ts-estree';
2-
import { AST, TSESTreeOptions, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
3-
import { ClassIndex, ClassLoaded } from './ClassIndex';
4-
import { ParameterDataField, ParameterLoader, ParameterRangeUnresolved } from './ParameterLoader';
1+
import type { ClassDeclaration, MethodDefinition } from '@typescript-eslint/types/dist/ts-estree';
2+
import type { AST, TSESTreeOptions } from '@typescript-eslint/typescript-estree';
3+
import { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
4+
import type { ClassIndex, ClassLoaded } from './ClassIndex';
5+
import type { ParameterDataField, ParameterRangeUnresolved } from './ParameterLoader';
6+
import { ParameterLoader } from './ParameterLoader';
57

68
/**
79
* Loads the constructor data of classes.

lib/parse/PackageMetadataLoader.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Path from 'path';
2-
import { ResolutionContext } from '../resolution/ResolutionContext';
2+
import type { ResolutionContext } from '../resolution/ResolutionContext';
33

44
/**
55
* Load metadata from packages.
@@ -22,8 +22,8 @@ export class PackageMetadataLoader {
2222
let packageJson: any;
2323
try {
2424
packageJson = JSON.parse(packageJsonRaw);
25-
} catch (error) {
26-
throw new Error(`Invalid package: Syntax error in ${packageJsonPath}: ${error.message}`);
25+
} catch (error: unknown) {
26+
throw new Error(`Invalid package: Syntax error in ${packageJsonPath}: ${(<Error> error).message}`);
2727
}
2828

2929
// Extract required fields from package.json
@@ -75,7 +75,7 @@ export interface PackageMetadata {
7575
version: string;
7676
moduleIri: string;
7777
componentsPath: string;
78-
contexts: {[iri: string]: string};
79-
importPaths: {[iri: string]: string};
78+
contexts: Record<string, string>;
79+
importPaths: Record<string, string>;
8080
typesPath: string;
8181
}

0 commit comments

Comments
 (0)