Skip to content

Commit 59a59d1

Browse files
committed
Improve lint config
1 parent 8b16852 commit 59a59d1

File tree

10 files changed

+24
-16
lines changed

10 files changed

+24
-16
lines changed

.eslintrc.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ module.exports = defineConfig({
3232
quotes: ['error', 'single', { avoidEscape: true }],
3333
semi: ['error', 'always'],
3434

35-
'@typescript-eslint/ban-ts-comment': 'off',
35+
'@typescript-eslint/array-type': ['warn', { default: 'array-simple', readonly: 'generic' }],
36+
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-expect-error': 'allow-with-description' }],
37+
'@typescript-eslint/ban-types': 'warn',
38+
'@typescript-eslint/consistent-type-imports': 'error',
3639
'@typescript-eslint/explicit-function-return-type': ['error', { allowExpressions: true }],
40+
'@typescript-eslint/explicit-member-accessibility': 'error',
3741
'@typescript-eslint/indent': ['error', 'tab', { SwitchCase: 1, ignoredNodes: ['MemberExpression'] }],
42+
'@typescript-eslint/lines-between-class-members': ['warn', 'always', { exceptAfterSingleLine: true }],
3843
'@typescript-eslint/member-ordering': 'warn',
3944
'@typescript-eslint/no-explicit-any': 'off',
4045
'@typescript-eslint/no-inferrable-types': 'off',
@@ -44,7 +49,9 @@ module.exports = defineConfig({
4449
'@typescript-eslint/no-unused-vars': 'off',
4550
'@typescript-eslint/prefer-nullish-coalescing': 'warn',
4651
'@typescript-eslint/prefer-optional-chain': 'warn',
47-
'@typescript-eslint/prefer-readonly': ['warn'],
52+
'@typescript-eslint/prefer-readonly': 'warn',
53+
'@typescript-eslint/prefer-reduce-type-parameter': 'warn',
54+
'@typescript-eslint/require-await': 'warn',
4855
'@typescript-eslint/restrict-template-expressions': 'off',
4956
'@typescript-eslint/typedef': ['warn', { memberVariableDeclaration: true, variableDeclaration: true }],
5057

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import type {
1212
} from 'prettier';
1313
import type { Token } from 'pug-lexer';
1414
import * as lex from 'pug-lexer';
15-
import { createLogger, Logger, LogLevel } from './logger';
15+
import type { Logger } from './logger';
16+
import { createLogger, LogLevel } from './logger';
1617
import type { PugParserOptions } from './options';
1718
import { options as pugOptions } from './options';
1819
import { convergeOptions } from './options/converge';

src/options/attribute-sorting/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function compareAttributeToken(
8686
* @param compare A function for comparing the values.
8787
* @returns The sorted array.
8888
*/
89-
export function stableSort<T>(array: readonly T[], compare: CompareFunction<T>): T[] {
89+
export function stableSort<T>(array: ReadonlyArray<T>, compare: CompareFunction<T>): T[] {
9090
const entries: Array<[T, number]> = array.map((value, index) => [value, index]);
9191
entries.sort((a, b) => {
9292
const order: CompareResult = compare(a[0], b[0]);
@@ -105,7 +105,7 @@ export function stableSort<T>(array: readonly T[], compare: CompareFunction<T>):
105105
* @param compareFn A function for comparing the values.
106106
* @returns The sorted array.
107107
*/
108-
export function partialSort<T>(arr: readonly T[], start: number, end: number, compareFn: CompareFunction<T>): T[] {
108+
export function partialSort<T>(arr: ReadonlyArray<T>, start: number, end: number, compareFn: CompareFunction<T>): T[] {
109109
const preSort: T[] = arr.slice(0, start);
110110
const postSort: T[] = arr.slice(end);
111111
const attributes: T[] = arr.slice(start, end);

src/options/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {
55
PUG_SORT_ATTRIBUTES_END_OPTION,
66
PUG_SORT_ATTRIBUTES_OPTION
77
} from './attribute-sorting';
8+
import type { ArrowParens } from './common';
89
import {
9-
ArrowParens,
1010
PUG_ARROW_PARENS_OPTION,
1111
PUG_BRACKET_SAME_LINE_OPTION,
1212
PUG_BRACKET_SPACING_OPTION,

src/printer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ export class PugPrinter {
318318
case 'eos':
319319
// TODO: These tokens write directly into the result
320320
this.result = results.join('');
321-
// @ts-expect-error
321+
// @ts-expect-error: The function is always valid
322322
this[token.type](token);
323323
results.length = 0;
324324
results.push(this.result);
@@ -335,7 +335,7 @@ export class PugPrinter {
335335
if (typeof this[token.type] !== 'function') {
336336
throw new Error('Unhandled token: ' + JSON.stringify(token));
337337
}
338-
// @ts-expect-error
338+
// @ts-expect-error: If the function would be invalid, it would be caught above
339339
results.push(this[token.type](token));
340340
break;
341341
}

tests/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AttributeToken } from 'pug-lexer';
1+
import type { AttributeToken } from 'pug-lexer';
22

33
/**
44
* Creates a fake attribute token.

tests/options/emptyAttributes/empty-attributes.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { readFileSync } from 'fs';
22
import { resolve } from 'path';
33
import { format } from 'prettier';
4-
import { AttributeToken } from 'pug-lexer';
5-
import { PugEmptyAttributes, PugEmptyAttributesForceQuotes } from '../../../src/options/empty-attributes';
4+
import type { AttributeToken } from 'pug-lexer';
5+
import type { PugEmptyAttributes, PugEmptyAttributesForceQuotes } from '../../../src/options/empty-attributes';
66
import { formatEmptyAttribute } from '../../../src/options/empty-attributes/utils';
77
import { createAttributeToken } from '../../common';
88
import { plugin } from './../../../src/index';

tests/options/pugExplicitDiv/pug-explicit-div.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { readFileSync } from 'fs';
22
import { resolve } from 'path';
3-
import { format, Options } from 'prettier';
3+
import type { Options } from 'prettier';
4+
import { format } from 'prettier';
45
import { plugin } from '../../../src/index';
56

67
describe('Options', () => {

tests/options/sortAttributes/sort-attributes.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { readFileSync } from 'fs';
22
import { resolve } from 'path';
33
import { format } from 'prettier';
4-
import { PugSortAttributes } from '../../../src/options/attribute-sorting/index';
4+
import type { PugSortAttributes } from '../../../src/options/attribute-sorting/index';
55
import { compareAttributeToken, stableSort } from '../../../src/options/attribute-sorting/utils';
66
import { createAttributeToken } from '../../common';
77
import { plugin } from './../../../src/index';
@@ -14,9 +14,8 @@ describe('Options', () => {
1414
const actual: string = format(code, {
1515
parser: 'pug',
1616
plugins: [plugin],
17-
// @ts-ignore
17+
1818
pugSortAttributesBeginning: ['v-for', ':key', 'src', 'alt'],
19-
// @ts-ignore
2019
pugSortAttributesEnd: ['@click']
2120
});
2221

tests/pragma/detect-pragma/detect-pragma.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { readFileSync } from 'fs';
22
import { resolve } from 'path';
3-
import { Parser } from 'prettier';
3+
import type { Parser } from 'prettier';
44
import { parsers } from './../../../src/index';
55

66
/* eslint @typescript-eslint/no-non-null-assertion: off */

0 commit comments

Comments
 (0)