Skip to content

Commit

Permalink
fix: configure array-type rule
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Jul 18, 2023
1 parent 5c8fd1d commit 55bff12
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
7 changes: 7 additions & 0 deletions base.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ module.exports = {
rules: {
// https://typescript-eslint.io/rules/

'@typescript-eslint/array-type': [
'error',
{
default: 'array-simple',
readonly: 'array-simple',
},
],
// Too noisy for now.
'@typescript-eslint/no-confusing-void-expression': 'off',
// Empty interfaces are common (React component props that extend others, AdonisJS default configs).
Expand Down
6 changes: 6 additions & 0 deletions test/notOk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ function testX(x: number) {
}

testX(x!);

function testY(y: (number | string)[]) {
return y;
}

testY([1, 2, 3, '4']);
6 changes: 3 additions & 3 deletions test/ok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export interface X {
* @param x - This is a x.
* @returns The best number in the world.
*/
function test(x: number) {
return x + 42;
function test(x: readonly number[]) {
return x[0] + 42;
}

test(1);
test([1]);

/**
* Logs 42.
Expand Down
1 change: 1 addition & 0 deletions test/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const errors = notOkResult.messages
.map((error) => error.ruleId)
.sort();
assert.deepStrictEqual(errors, [
'@typescript-eslint/array-type',
'@typescript-eslint/no-non-null-assertion',
'@typescript-eslint/no-unnecessary-type-assertion',
]);
Expand Down

0 comments on commit 55bff12

Please sign in to comment.