Skip to content

Commit e7d6f99

Browse files
authored
Add TypeScript-aware linting via typescript-eslint (#1429)
1 parent bf6343b commit e7d6f99

15 files changed

+518
-37
lines changed

eslint.config.js

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
11
import babelParser from '@babel/eslint-parser';
22
import js from '@eslint/js';
33
import { defineConfig } from 'eslint/config';
4+
import chaiFriendly from 'eslint-plugin-chai-friendly';
45
import importPlugin from 'eslint-plugin-import';
56
import prettierRecommended from 'eslint-plugin-prettier/recommended';
67
import unusedImports from 'eslint-plugin-unused-imports';
78
import globals from 'globals';
9+
import ts from 'typescript-eslint';
810

9-
export default defineConfig([
11+
const noUnusedVarsRule = [
12+
'error',
13+
{
14+
argsIgnorePattern: '^_',
15+
varsIgnorePattern: '^_',
16+
caughtErrorsIgnorePattern: '^_',
17+
},
18+
];
19+
20+
export default defineConfig(
1021
js.configs.recommended,
22+
ts.configs.recommended,
23+
ts.configs.stylistic,
1124
prettierRecommended,
25+
chaiFriendly.configs.recommendedFlat,
1226

27+
// all files
1328
{
1429
languageOptions: {
1530
ecmaVersion: 2021,
31+
sourceType: 'module',
1632
},
1733
plugins: {
1834
import: importPlugin,
1935
'unused-imports': unusedImports,
36+
'chai-friendly': chaiFriendly,
2037
},
2138
rules: {
2239
complexity: ['error', { max: 35 }],
@@ -42,32 +59,44 @@ export default defineConfig([
4259
'newlines-between': 'always',
4360
},
4461
],
45-
'no-unused-vars': [
62+
'no-unused-vars': noUnusedVarsRule,
63+
'@typescript-eslint/no-unused-vars': noUnusedVarsRule,
64+
'@typescript-eslint/no-empty-function': [
4665
'error',
4766
{
48-
argsIgnorePattern: '^_',
49-
varsIgnorePattern: '^_',
50-
caughtErrorsIgnorePattern: '^_',
67+
allow: ['arrowFunctions'],
5168
},
5269
],
70+
71+
// disabled for now
72+
'@typescript-eslint/consistent-indexed-object-style': 'off',
73+
'@typescript-eslint/consistent-type-assertions': 'off',
74+
'@typescript-eslint/consistent-type-definitions': 'off',
75+
'@typescript-eslint/no-explicit-any': 'off',
76+
'@typescript-eslint/no-this-alias': 'off',
77+
'@typescript-eslint/prefer-for-of': 'off',
78+
'@typescript-eslint/prefer-function-type': 'off',
79+
'chai-friendly/no-unused-expressions': 'off',
80+
'no-undef': 'off',
81+
'no-var': 'off',
5382
},
5483
},
5584

5685
// globals
5786
{
58-
files: ['test/**/*.js'],
87+
files: ['test/**/*.[tj]s'],
5988
languageOptions: { globals: { ...globals.mocha } },
6089
},
6190
{
62-
files: ['src/**/*.{js,cjs}', 'test/**/*.js'],
91+
files: ['src/**/*.c?[tj]s', 'test/**/*.[tj]s'],
6392
languageOptions: { globals: { ...globals.browser } },
6493
},
6594
{
6695
files: [
67-
'src/server/**/*.js',
68-
'src/react-native/**/*.js',
69-
'test/**/server.*.js',
70-
'scripts/**/*.js',
96+
'src/server/**/*.[tj]s',
97+
'src/react-native/**/*.[tj]s',
98+
'test/**/server.*.[tj]s',
99+
'scripts/**/*.[tj]s',
71100
],
72101
languageOptions: { globals: { ...globals.node } },
73102
},
@@ -82,14 +111,34 @@ export default defineConfig([
82111
ecmaVersion: 2021,
83112
},
84113
},
85-
rules: { strict: ['error', 'safe'] },
114+
rules: {
115+
strict: ['error', 'safe'],
116+
'@typescript-eslint/no-unused-vars': 'off',
117+
},
118+
},
119+
120+
// ts
121+
{
122+
files: ['**/*.ts'],
123+
rules: {
124+
'no-unused-vars': 'off',
125+
},
86126
},
87127

88128
// cjs
89129
{
90130
files: ['**/*.cjs'],
91131
languageOptions: { sourceType: 'commonjs' },
92-
rules: { strict: 'off' },
132+
rules: {
133+
strict: 'off',
134+
'@typescript-eslint/no-require-imports': 'off',
135+
},
136+
},
137+
138+
// tests
139+
{
140+
files: ['test/**/*.[tj]s'],
141+
rules: { '@typescript-eslint/no-empty-function': 'off' },
93142
},
94143

95144
// scripts
@@ -101,4 +150,4 @@ export default defineConfig([
101150
{
102151
ignores: ['dist', 'examples', 'node_modules', 'vendor', 'coverage'],
103152
},
104-
]);
153+
);

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ declare namespace Rollbar {
304304
plugins?: any[];
305305
}
306306

307-
export type TransformSpanParams = { span: any; }
307+
export type TransformSpanParams = { span: any };
308308
export interface TracingOptions {
309309
enabled?: boolean;
310310
endpoint?: string;

0 commit comments

Comments
 (0)