Skip to content

Commit ed1ff34

Browse files
author
Luis Fernando Planella Gonzalez
committed
Replaced TSLint by ESLint
Fixes #277
1 parent b3d9791 commit ed1ff34

11 files changed

+9897
-1759
lines changed

.eslintrc.js

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
module.exports = {
2+
"env": {
3+
"es6": true,
4+
"node": true
5+
},
6+
"parser": "@typescript-eslint/parser",
7+
"parserOptions": {
8+
"project": "tsconfig.json",
9+
"sourceType": "module"
10+
},
11+
"plugins": [
12+
"eslint-plugin-jsdoc",
13+
"@typescript-eslint",
14+
"@typescript-eslint/tslint"
15+
],
16+
"root": true,
17+
"rules": {
18+
"@typescript-eslint/indent": [
19+
"error",
20+
2
21+
],
22+
"@typescript-eslint/member-delimiter-style": [
23+
"error",
24+
{
25+
"multiline": {
26+
"delimiter": "semi",
27+
"requireLast": true
28+
},
29+
"singleline": {
30+
"delimiter": "semi",
31+
"requireLast": false
32+
}
33+
}
34+
],
35+
"@typescript-eslint/naming-convention": "error",
36+
"@typescript-eslint/no-shadow": [
37+
"error",
38+
{
39+
"hoist": "all"
40+
}
41+
],
42+
"@typescript-eslint/prefer-namespace-keyword": "error",
43+
"@typescript-eslint/quotes": [
44+
"error",
45+
"single"
46+
],
47+
"@typescript-eslint/semi": [
48+
"error",
49+
"always"
50+
],
51+
"@typescript-eslint/type-annotation-spacing": "error",
52+
"brace-style": [
53+
"error",
54+
"1tbs"
55+
],
56+
"eol-last": "error",
57+
"eqeqeq": [
58+
"error",
59+
"smart"
60+
],
61+
"guard-for-in": "error",
62+
"indent": "off",
63+
"jsdoc/check-alignment": "error",
64+
"jsdoc/check-indentation": "error",
65+
"no-shadow": "off",
66+
"no-throw-literal": "error",
67+
"no-trailing-spaces": "error",
68+
"no-var": "error",
69+
"prefer-const": "error",
70+
"quotes": "off",
71+
"semi": "off",
72+
"spaced-comment": [
73+
"error",
74+
"always",
75+
{
76+
"markers": [
77+
"/"
78+
]
79+
}
80+
],
81+
"@typescript-eslint/tslint/config": [
82+
"error",
83+
{
84+
"rules": {
85+
"whitespace": [
86+
true,
87+
"check-branch",
88+
"check-decl",
89+
"check-operator",
90+
"check-module",
91+
"check-separator",
92+
"check-type"
93+
]
94+
}
95+
}
96+
]
97+
}
98+
};

lib/cmd-args.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ import { Options } from './options.js';
55
import fs from 'fs';
66
import { kebabCase } from 'lodash';
77

8-
const Mnemonics: { [key: string]: string } = { 'input': 'i', 'output': 'o' };
9-
const DefaultConfig = 'ng-openapi-gen.json';
8+
const MNEMONICS: { [key: string]: string } = { 'input': 'i', 'output': 'o' };
9+
const DEFAULT = 'ng-openapi-gen.json';
1010

1111
function createParser() {
1212
const argParser = new ArgumentParser({
13+
// eslint-disable-next-line @typescript-eslint/naming-convention
1314
add_help: true,
1415
description: `
1516
Generator for API clients described with OpenAPI 3.0 specification for
1617
Angular 6+ projects. Requires a configuration file, which defaults to
17-
${DefaultConfig} in the current directory. The file can also be
18+
${DEFAULT} in the current directory. The file can also be
1819
specified using '--config <file>' or '-c <file>'.
19-
All settings in the configuration file can be overridding by setting the
20+
All settings in the configuration file can be overriding by setting the
2021
corresponding argument in the command-line. For example, to specify a
2122
custom suffix for service classes via command-line, pass the command-line
2223
argument '--serviceSuffix Suffix'. Kebab-case is also accepted, so, the same
@@ -38,9 +39,9 @@ a configuration file is only required if no --input argument is set.`.trim()
3839
{
3940
help: `
4041
The configuration file to be used. If not specified, assumes that
41-
${DefaultConfig} in the current directory`.trim(),
42+
${DEFAULT} in the current directory`.trim(),
4243
dest: 'config',
43-
default: `./${DefaultConfig}`
44+
default: `./${DEFAULT}`
4445
}
4546
);
4647
const props = schema.properties;
@@ -51,7 +52,7 @@ ${DefaultConfig} in the current directory`.trim(),
5152
const kebab = kebabCase(key);
5253
const desc = (props as any)[key];
5354
const names = [];
54-
const mnemonic = Mnemonics[key];
55+
const mnemonic = MNEMONICS[key];
5556
if (mnemonic) {
5657
names.push('-' + mnemonic);
5758
}
@@ -77,9 +78,9 @@ export function parseOptions(sysArgs?: string[]): Options {
7778
if (args.config) {
7879
if (fs.existsSync(args.config)) {
7980
options = JSON.parse(fs.readFileSync(args.config, { encoding: 'utf-8' }));
80-
} else if (args.config === `./${DefaultConfig}`) {
81+
} else if (args.config === `./${DEFAULT}`) {
8182
if ((args.input || '').length === 0) {
82-
throw new Error(`No input is given, and the file ${DefaultConfig} doesn't exist.
83+
throw new Error(`No input is given, and the file ${DEFAULT} doesn't exist.
8384
For help, run ng-openapi-gen --help`);
8485
}
8586
} else {
@@ -111,7 +112,7 @@ For help, run ng-openapi-gen --help`);
111112
options[key] = value;
112113
}
113114
}
114-
if (options.input == undefined || options.input === '') {
115+
if (options.input === undefined || options.input === '') {
115116
throw new Error('No input (OpenAPI specification) defined');
116117
}
117118
return options;

lib/content.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { tsType } from './gen-utils';
66
* Either a request body or response content
77
*/
88
export class Content {
9-
109
type: string;
1110

1211
constructor(

lib/gen-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export function toBasicChars(text: string, firstNonDigit = false): string {
120120
*/
121121
export function tsComments(description: string | undefined, level: number, deprecated?: boolean) {
122122
const indent = ' '.repeat(level);
123-
if (description == undefined || description.length === 0) {
123+
if (description === undefined || description.length === 0) {
124124
return indent + (deprecated ? '/** @deprecated */' : '');
125125
}
126126
const lines = description.trim().split('\n');

lib/globals.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ export class Globals {
3232
this.responseClass = options.response || 'StrictHttpResponse';
3333
this.responseFile = fileName(this.responseClass);
3434
if (options.module !== false && options.module !== '') {
35-
this.moduleClass = options.module === true || options.module == undefined ? 'ApiModule' : options.module;
35+
this.moduleClass = options.module === true || options.module === undefined ? 'ApiModule' : options.module;
3636
// Angular's best practices demands xxx.module.ts, not xxx-module.ts
3737
this.moduleFile = fileName(this.moduleClass as string).replace(/\-module$/, '.module');
3838
}
3939
if (options.serviceIndex !== false && options.serviceIndex !== '') {
40-
this.serviceIndexFile = options.serviceIndex === true || options.serviceIndex == undefined ? 'services' : options.serviceIndex;
40+
this.serviceIndexFile = options.serviceIndex === true || options.serviceIndex === undefined ? 'services' : options.serviceIndex;
4141
}
4242
if (options.modelIndex !== false && options.modelIndex !== '') {
43-
this.modelIndexFile = options.modelIndex === true || options.modelIndex == undefined ? 'models' : options.modelIndex;
43+
this.modelIndexFile = options.modelIndex === true || options.modelIndex === undefined ? 'models' : options.modelIndex;
4444
}
4545
}
4646

lib/ng-openapi-gen.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1+
import $RefParser from '@apidevtools/json-schema-ref-parser';
12
import { OpenAPIObject, OperationObject, PathItemObject, ReferenceObject, SchemaObject } from '@loopback/openapi-v3-types';
3+
import eol from 'eol';
24
import fs from 'fs-extra';
3-
import $RefParser, { HTTPResolverOptions } from '@apidevtools/json-schema-ref-parser';
4-
import mkdirp from 'mkdirp';
5-
import path from 'path';
65
import os from 'os';
6+
import path from 'path';
77
import { parseOptions } from './cmd-args';
8-
import { HTTP_METHODS, methodName, simpleName, syncDirs, deleteDirRecursive } from './gen-utils';
8+
import { HTTP_METHODS, deleteDirRecursive, methodName, simpleName, syncDirs } from './gen-utils';
99
import { Globals } from './globals';
1010
import { HandlebarsManager } from './handlebars-manager';
1111
import { Import } from './imports';
12+
import { Logger } from './logger';
1213
import { Model } from './model';
1314
import { Operation } from './operation';
1415
import { Options } from './options';
1516
import { Service } from './service';
1617
import { Templates } from './templates';
17-
import eol from 'eol';
18-
import { Logger } from './logger';
1918

2019
/**
2120
* Main generator class
@@ -128,7 +127,8 @@ export class NgOpenApiGen {
128127
const ts = this.setEndOfLine(this.templates.apply(template, model));
129128
const file = path.join(this.tempDir, subDir || '.', `${baseName}.ts`);
130129
const dir = path.dirname(file);
131-
mkdirp.sync(dir);
130+
131+
fs.mkdirpSync(dir);
132132
fs.writeFileSync(file, ts, { encoding: 'utf-8' });
133133
}
134134

@@ -322,8 +322,6 @@ export class NgOpenApiGen {
322322
}
323323
}
324324

325-
///////////////////////////////////////////////////////////////////////////
326-
327325
/**
328326
* Parses the command-line arguments, reads the configuration file and run the generation
329327
*/
@@ -339,7 +337,7 @@ export async function runNgOpenApiGen() {
339337
resolve: {
340338
http: {
341339
timeout: options.fetchTimeout == null ? 20000 : options.fetchTimeout
342-
} as HTTPResolverOptions
340+
}
343341
}
344342
}) as OpenAPIObject;
345343
const gen = new NgOpenApiGen(openApi, options);

lib/operation.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ export class Operation {
101101
}
102102

103103
private collectSecurity(params: (SecurityRequirementObject)[] | undefined): Security[][] {
104-
if (!params) { return []; }
104+
if (!params) {
105+
return [];
106+
}
105107

106108
return params.map((param) => {
107109
return Object.keys(param).map(key => {
@@ -127,7 +129,7 @@ export class Operation {
127129
return result;
128130
}
129131

130-
private collectResponses(): { success: Response | undefined, all: Response[] } {
132+
private collectResponses(): { success: Response | undefined; all: Response[] } {
131133
let successResponse: Response | undefined = undefined;
132134
const allResponses: Response[] = [];
133135
const responses = this.spec.responses || {};

lib/options.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ export interface Options {
100100

101101
customizedResponseType?: {
102102
[key: string]: {
103-
toUse: 'arraybuffer' | 'blob' | 'json' | 'document'
104-
}
103+
toUse: 'arraybuffer' | 'blob' | 'json' | 'document';
104+
};
105105
};
106106

107107
/** When specified, will create temporary files in system temporary folder instead of next to output folder. */

0 commit comments

Comments
 (0)