eslint.config.ts•3.08 kB
import js from '@eslint/js';
import tseslint from '@typescript-eslint/eslint-plugin';
import tsparser from '@typescript-eslint/parser';
import type { Linter } from 'eslint';
/**
* ESLint configuration for Grafana MCP Server
* Supports both TypeScript and JavaScript files with strict TypeScript rules
*/
const config: Linter.FlatConfig[] = [
js.configs.recommended,
{
files: ['src/**/*.ts', 'src/**/*.tsx'],
languageOptions: {
parser: tsparser,
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
project: './tsconfig.json',
},
globals: {
console: 'readonly',
process: 'readonly',
Buffer: 'readonly',
__dirname: 'readonly',
__filename: 'readonly',
global: 'readonly',
setTimeout: 'readonly',
setInterval: 'readonly',
clearTimeout: 'readonly',
clearInterval: 'readonly',
URLSearchParams: 'readonly',
},
},
plugins: {
'@typescript-eslint': tseslint,
},
rules: {
// Core JavaScript rules
'no-console': 'off', // Allow console.log for debugging in this context
'no-debugger': 'error',
'no-unreachable': 'error',
'prefer-const': 'error',
'prefer-template': 'error',
'no-unused-vars': 'off', // Disable JS version in favor of TS version
// TypeScript specific rules
'@typescript-eslint/no-unused-vars': ['error', {
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_'
}],
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/no-unused-expressions': 'error',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/await-thenable': 'error',
// Style consistency
'quotes': ['error', 'single', { avoidEscape: true }],
'semi': ['error', 'always'],
'comma-dangle': ['error', 'always-multiline'],
'object-curly-spacing': ['error', 'always'],
'array-bracket-spacing': ['error', 'never'],
},
},
{
files: ['**/*.js', '**/*.mjs'],
languageOptions: {
ecmaVersion: 2022,
sourceType: 'module',
},
rules: {
...js.configs.recommended.rules,
'no-console': 'off',
'quotes': ['error', 'single'],
'semi': ['error', 'always'],
'prefer-const': 'error',
'prefer-template': 'error',
},
},
{
// Configuration files can remain as JS for compatibility
files: ['*.config.js', '*.config.mjs'],
languageOptions: {
ecmaVersion: 2022,
sourceType: 'module',
},
rules: {
'no-console': 'off',
},
},
{
ignores: [
'build/**/*',
'dist/**/*',
'node_modules/**/*',
'*.d.ts',
'coverage/**/*',
],
},
];
export default config;