Skip to content

Commit

Permalink
Improve lint config
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Dec 4, 2021
1 parent 8b16852 commit 59a59d1
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 16 deletions.
11 changes: 9 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ module.exports = defineConfig({
quotes: ['error', 'single', { avoidEscape: true }],
semi: ['error', 'always'],

'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/array-type': ['warn', { default: 'array-simple', readonly: 'generic' }],
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-expect-error': 'allow-with-description' }],
'@typescript-eslint/ban-types': 'warn',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/explicit-function-return-type': ['error', { allowExpressions: true }],
'@typescript-eslint/explicit-member-accessibility': 'error',
'@typescript-eslint/indent': ['error', 'tab', { SwitchCase: 1, ignoredNodes: ['MemberExpression'] }],
'@typescript-eslint/lines-between-class-members': ['warn', 'always', { exceptAfterSingleLine: true }],
'@typescript-eslint/member-ordering': 'warn',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
Expand All @@ -44,7 +49,9 @@ module.exports = defineConfig({
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'warn',
'@typescript-eslint/prefer-optional-chain': 'warn',
'@typescript-eslint/prefer-readonly': ['warn'],
'@typescript-eslint/prefer-readonly': 'warn',
'@typescript-eslint/prefer-reduce-type-parameter': 'warn',
'@typescript-eslint/require-await': 'warn',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/typedef': ['warn', { memberVariableDeclaration: true, variableDeclaration: true }],

Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import type {
} from 'prettier';
import type { Token } from 'pug-lexer';
import * as lex from 'pug-lexer';
import { createLogger, Logger, LogLevel } from './logger';
import type { Logger } from './logger';
import { createLogger, LogLevel } from './logger';
import type { PugParserOptions } from './options';
import { options as pugOptions } from './options';
import { convergeOptions } from './options/converge';
Expand Down
4 changes: 2 additions & 2 deletions src/options/attribute-sorting/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function compareAttributeToken(
* @param compare A function for comparing the values.
* @returns The sorted array.
*/
export function stableSort<T>(array: readonly T[], compare: CompareFunction<T>): T[] {
export function stableSort<T>(array: ReadonlyArray<T>, compare: CompareFunction<T>): T[] {
const entries: Array<[T, number]> = array.map((value, index) => [value, index]);
entries.sort((a, b) => {
const order: CompareResult = compare(a[0], b[0]);
Expand All @@ -105,7 +105,7 @@ export function stableSort<T>(array: readonly T[], compare: CompareFunction<T>):
* @param compareFn A function for comparing the values.
* @returns The sorted array.
*/
export function partialSort<T>(arr: readonly T[], start: number, end: number, compareFn: CompareFunction<T>): T[] {
export function partialSort<T>(arr: ReadonlyArray<T>, start: number, end: number, compareFn: CompareFunction<T>): T[] {
const preSort: T[] = arr.slice(0, start);
const postSort: T[] = arr.slice(end);
const attributes: T[] = arr.slice(start, end);
Expand Down
2 changes: 1 addition & 1 deletion src/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
PUG_SORT_ATTRIBUTES_END_OPTION,
PUG_SORT_ATTRIBUTES_OPTION
} from './attribute-sorting';
import type { ArrowParens } from './common';
import {
ArrowParens,
PUG_ARROW_PARENS_OPTION,
PUG_BRACKET_SAME_LINE_OPTION,
PUG_BRACKET_SPACING_OPTION,
Expand Down
4 changes: 2 additions & 2 deletions src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export class PugPrinter {
case 'eos':
// TODO: These tokens write directly into the result
this.result = results.join('');
// @ts-expect-error
// @ts-expect-error: The function is always valid
this[token.type](token);
results.length = 0;
results.push(this.result);
Expand All @@ -335,7 +335,7 @@ export class PugPrinter {
if (typeof this[token.type] !== 'function') {
throw new Error('Unhandled token: ' + JSON.stringify(token));
}
// @ts-expect-error
// @ts-expect-error: If the function would be invalid, it would be caught above
results.push(this[token.type](token));
break;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AttributeToken } from 'pug-lexer';
import type { AttributeToken } from 'pug-lexer';

/**
* Creates a fake attribute token.
Expand Down
4 changes: 2 additions & 2 deletions tests/options/emptyAttributes/empty-attributes.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { format } from 'prettier';
import { AttributeToken } from 'pug-lexer';
import { PugEmptyAttributes, PugEmptyAttributesForceQuotes } from '../../../src/options/empty-attributes';
import type { AttributeToken } from 'pug-lexer';
import type { PugEmptyAttributes, PugEmptyAttributesForceQuotes } from '../../../src/options/empty-attributes';
import { formatEmptyAttribute } from '../../../src/options/empty-attributes/utils';
import { createAttributeToken } from '../../common';
import { plugin } from './../../../src/index';
Expand Down
3 changes: 2 additions & 1 deletion tests/options/pugExplicitDiv/pug-explicit-div.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { format, Options } from 'prettier';
import type { Options } from 'prettier';
import { format } from 'prettier';
import { plugin } from '../../../src/index';

describe('Options', () => {
Expand Down
5 changes: 2 additions & 3 deletions tests/options/sortAttributes/sort-attributes.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { format } from 'prettier';
import { PugSortAttributes } from '../../../src/options/attribute-sorting/index';
import type { PugSortAttributes } from '../../../src/options/attribute-sorting/index';
import { compareAttributeToken, stableSort } from '../../../src/options/attribute-sorting/utils';
import { createAttributeToken } from '../../common';
import { plugin } from './../../../src/index';
Expand All @@ -14,9 +14,8 @@ describe('Options', () => {
const actual: string = format(code, {
parser: 'pug',
plugins: [plugin],
// @ts-ignore

pugSortAttributesBeginning: ['v-for', ':key', 'src', 'alt'],
// @ts-ignore
pugSortAttributesEnd: ['@click']
});

Expand Down
2 changes: 1 addition & 1 deletion tests/pragma/detect-pragma/detect-pragma.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { Parser } from 'prettier';
import type { Parser } from 'prettier';
import { parsers } from './../../../src/index';

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

0 comments on commit 59a59d1

Please sign in to comment.