Skip to content

Commit

Permalink
Merge pull request #153 from dmanto/migrate-to-eslint-9.x
Browse files Browse the repository at this point in the history
Migrate to latest ESLint Version
  • Loading branch information
kraih authored Sep 3, 2024
2 parents 415e945 + cbf9e0a commit 1f1f60c
Show file tree
Hide file tree
Showing 18 changed files with 156 additions and 82 deletions.
37 changes: 0 additions & 37 deletions .eslintrc.json

This file was deleted.

115 changes: 115 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import importPlugin from 'eslint-plugin-import-x';
import globals from 'globals';
import tsParser from '@typescript-eslint/parser';
import eslintJs from '@eslint/js';
import eslintTs from 'typescript-eslint';

const tsFiles = ['{src,test}/**/*.ts'];
const jsFiles = ['test/**/*.js'];

const languageOptions = {
globals: {
...globals.node
},
ecmaVersion: 2023,
sourceType: 'module'
};

const customTypescriptConfig = {
files: tsFiles,
plugins: {
import: importPlugin,
'import/parsers': tsParser
},
languageOptions: {
...languageOptions,
parser: tsParser,
parserOptions: {
project: './tsconfig.eslint.json'
}
},
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts']
}
},
rules: {
'import/export': 'error',
'import/no-duplicates': 'warn',
...importPlugin.configs.typescript.rules,
'@typescript-eslint/no-use-before-define': 'off',
'require-await': 'off',
'no-duplicate-imports': 'error',
'no-unneeded-ternary': 'error',
'prefer-object-spread': 'error',

'@typescript-eslint/no-unused-vars': [
'error',
{
ignoreRestSiblings: true,
args: 'none'
}
],
'import/order': [
'error',
{
groups: ['type', 'builtin', ['sibling', 'parent'], 'index', 'object'],
'newlines-between': 'never',

alphabetize: {
order: 'asc',
caseInsensitive: true
}
}
],

'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports'
}
],

'@typescript-eslint/no-explicit-any': 'off'
}
};

const customJavascriptConfig = {
files: jsFiles,
languageOptions: {
...languageOptions,
parserOptions: {
ecmaVersion: 2023
}
},
rules: {
'no-duplicate-imports': 'error',
'no-unneeded-ternary': 'error',
'prefer-object-spread': 'error',
'no-unused-vars': [
'error',
{
ignoreRestSiblings: true,
args: 'none'
}
]
}
};
const recommendedTypeScriptConfigs = [
...eslintTs.configs.recommended.map(config => ({
...config,
files: tsFiles
})),
...eslintTs.configs.stylistic.map(config => ({
...config,
files: tsFiles
}))
];

export default [
{ignores: ['docs/*', 'lib/*']},
eslintJs.configs.recommended,
customJavascriptConfig,
...recommendedTypeScriptConfigs,
customTypescriptConfig
];
19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
"clean": "rm -rf tsconfig.tsbuildinfo test/support/ts/full-app/tsconfig.tsbuildinfo lib test/support/ts/full-app/lib",
"coverage": "c8 tap --disable-coverage --allow-empty-coverage test/*.js test/*.ts",
"coverage:ci": "c8 --reporter lcovonly tap --disable-coverage --allow-empty-coverage test/*.js test/*.ts",
"prelint": "prettier --check \"{src,test}/**/*.{js,ts}\" eslint.config.js",
"prelint:fix": "prettier --write \"{src,test}/**/*.{js,ts}\" eslint.config.js",
"lint": "eslint \"test/*.js\" \"test/support/js/**/*.js\" \"test/support/ts/**/src/**/*.ts\" \"src/**/*.ts\" \"src/*.ts\"",
"lint:fix": "npm run lint -- --fix",
"prepublishOnly": "npm run build",
Expand All @@ -53,6 +55,7 @@
"mojo": "./bin/mojo.js"
},
"devDependencies": {
"@eslint/js": "^9.9.1",
"@types/busboy": "^1.5.0",
"@types/js-yaml": "^4.0.3",
"@types/mime-types": "^2.1.0",
Expand All @@ -62,24 +65,26 @@
"@types/stack-utils": "^2.0.1",
"@types/tough-cookie": "^4.0.2",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/eslint-plugin": "^8.3.0",
"@typescript-eslint/parser": "^8.3.0",
"autocannon": "^7.3.0",
"c8": "^10.1.0",
"concurrently": "^8.0.0",
"eslint": "^8.1.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.23.4",
"eslint": "^9.9.1",
"eslint-plugin-import-x": "^4.1.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^5.0.0",
"globals": "^15.9.0",
"nodemon": "^3.0.0",
"prettier": "^3.0.0",
"prettier": "^3.3.3",
"tap": "^21.0.0",
"typescript": "^5.2.0"
"typescript": "^5.5.4",
"typescript-eslint": "^8.3.0"
},
"engines": {
"node": ">= 16"
},
"dependencies": {
"@eslint/compat": "^1.1.1",
"@mojojs/dom": "^2.1.0",
"@mojojs/path": "^1.6.0",
"@mojojs/template": "^2.2.0",
Expand Down
3 changes: 1 addition & 2 deletions src/cgi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type {MojoApp, ServerResponseBody} from './types.js';
import type {Readable} from 'node:stream';
import {Stream} from 'node:stream';
import {Stream, type Readable} from 'node:stream';
import {ServerRequest} from './server/request.js';
import {ServerResponse} from './server/response.js';
import {httpStatusMessages} from './util.js';
Expand Down
6 changes: 2 additions & 4 deletions src/plugins/default-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import type {
URLTarget,
UserAgentRequestOptions
} from '../types.js';
import type {InspectOptions} from 'node:util';
import {inspect} from 'node:util';
import {inspect, type InspectOptions} from 'node:util';
import {Logger} from '../logger.js';
import {SafeString} from '../util.js';
import {exceptionContext} from '../util.js';
import {exceptionContext, SafeString} from '../util.js';
import DOM from '@mojojs/dom';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/tmpl-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function tmplEnginePlugin(app: App): void {
}

class TmplEngine {
cache: Cache<(data?: Record<string, any>) => Promise<string>> = new Cache();
cache = new Cache<(data?: Record<string, any>) => Promise<string>>();

async render(ctx: MojoContext, options: MojoRenderOptions): Promise<Buffer> {
let template;
Expand Down
1 change: 1 addition & 0 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export class Router extends Route {
const customNames: RouteIndex = {};

const children = [...this.children];
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < children.length; i++) {
const child = children[i];
if (child.customName !== undefined && customNames[child.customName] === undefined) {
Expand Down
4 changes: 1 addition & 3 deletions src/router/pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import {escapeRegExp} from '@mojojs/util';
interface MatchOptions {
isEndpoint: boolean;
}
interface PlaceholderTypes {
[name: string]: PlaceholderType;
}
type PlaceholderTypes = Record<string, PlaceholderType>;

type ASTNode = [symbol, ...string[]];

Expand Down
2 changes: 1 addition & 1 deletion src/router/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class Plan {
/**
* Steps in route.
*/
steps: Array<Record<string, any>> = [];
steps: Record<string, any>[] = [];
/**
* Dispatch stops in route.
*/
Expand Down
8 changes: 4 additions & 4 deletions src/router/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Route {
/**
* Activate conditions for this route.
*/
requirements: Array<Record<string, any>> = [];
requirements: Record<string, any>[] = [];
/**
* Activate `websocket` semantics for this route.
*/
Expand Down Expand Up @@ -255,7 +255,7 @@ export class Route {
/**
* Set default parameters for this route.
*/
to(...targets: Array<string | MojoAction | Record<string, any>>): this {
to(...targets: (string | MojoAction | Record<string, any>)[]): this {
const {defaults} = this.pattern;

for (const target of targets) {
Expand Down Expand Up @@ -299,8 +299,8 @@ export class Route {
return child;
}

_branch(): Array<Router | Route> {
const branch: Array<Router | Route> = [this];
_branch(): (Router | Route)[] {
const branch: (Router | Route)[] = [this];
let current: Router | Route | undefined = branch[0];
while ((current = current.parent) !== undefined) {
branch.push(current);
Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Server {

_cluster: boolean;
_listen: string[];
_servers: Array<http.Server | https.Server> = [];
_servers: (http.Server | https.Server)[] = [];
_quiet: boolean;
_workers: number;

Expand Down
2 changes: 1 addition & 1 deletion src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class Session {
decipher.setAuthTag(authTag);
const decrypted = decipher.update(value, 'base64', 'utf8');
return decrypted + decipher.final('utf8');
} catch (error) {
} catch {
continue;
}
}
Expand Down
19 changes: 8 additions & 11 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import type {Route} from './router/route.js';
import type {SafeString} from './util.js';
import type {ValidatorResult} from './validator/result.js';
import type {Agent} from 'node:http';
import type {Readable} from 'node:stream';
import type {Stream} from 'node:stream';
import type {Readable, Stream} from 'node:stream';
import type {URL} from 'node:url';
import type {InspectOptions} from 'node:util';
import type {Test} from 'tap';
Expand Down Expand Up @@ -45,9 +44,7 @@ export interface MojoContext extends Context {

export type MojoAction = (ctx: MojoContext, ...args: any[]) => any;

export interface MojoModels {
[key: string]: any;
}
export type MojoModels = Record<string, any>;

export interface MojoTags {
asset: (path: string, attrs?: TagAttrs) => Promise<SafeString>;
Expand Down Expand Up @@ -84,8 +81,8 @@ export interface MojoTags {
[key: string]: any;
}

export type AnyArguments = Array<string | string[] | MojoAction | Record<string, string[] | RegExp>>;
export type RouteArguments = Array<string | MojoAction | Record<string, string[] | RegExp>>;
export type AnyArguments = (string | string[] | MojoAction | Record<string, string[] | RegExp>)[];
export type RouteArguments = (string | MojoAction | Record<string, string[] | RegExp>)[];
export type PlaceholderType = RegExp | string | string[];

export type TagAttrs = Record<string, string | boolean | Record<string, string>>;
Expand All @@ -102,8 +99,8 @@ export interface BackendInfo {
export interface SessionData {
expiration?: number;
expires?: number;
flash?: {[key: string]: any};
nextFlash?: {[key: string]: any};
flash?: Record<string, any>;
nextFlash?: Record<string, any>;
[key: string]: any;
}

Expand All @@ -130,12 +127,12 @@ export interface CookieOptions {
secure?: boolean;
}

export type MojoURLOptions = {
export interface MojoURLOptions {
absolute?: boolean;
fragment?: string;
query?: Record<string, string | string[]>;
values?: Record<string, string>;
};
}

export interface MojoRenderOptions {
engine?: string;
Expand Down
3 changes: 1 addition & 2 deletions src/user-agent/cookie-jar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {URL} from 'node:url';
import {format} from 'node:url';
import {format, type URL} from 'node:url';
import tough from 'tough-cookie';

/**
Expand Down
Loading

0 comments on commit 1f1f60c

Please sign in to comment.