// Copyright (c) 2026 The Brave Authors. All rights reserved. // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this file, // You can obtain one at https://mozilla.org/MPL/2.0/. import { defineConfig, globalIgnores } from 'eslint/config' import jest from 'eslint-plugin-jest' import importPlugin from 'eslint-plugin-import' import licenses from 'eslint-plugin-licenses' import noUnsanitized from 'eslint-plugin-no-unsanitized' import reactHooks from 'eslint-plugin-react-hooks' import love from 'eslint-config-love' import prettier from 'eslint-config-prettier/flat' import tslint from 'typescript-eslint' import eslintJs from '@eslint/js' import globals from 'globals' // Config layout: each plugin or override is a separate array entry. // Guidelines: // - One section per plugin; do not combine rules from different plugins // in one section. // - Each section should have a comment stating its purpose and which files // it targets. // Verify changes with: npm run eslint (about 1 min). export default defineConfig([ // Setup project-wide language options. { languageOptions: { globals: { ...globals.browser, ...globals.jest, ...globals.node, chrome: 'readonly', }, }, }, // Turn off rules that conflict with Prettier formatting (all files). prettier, // ESLint core recommended rules for JavaScript (.js files + related). eslintJs.configs.recommended, // Prevents unsafe DOM injection, e.g. innerHTML (all files). noUnsanitized.configs.recommended, // React Hooks rules and related React best practices (.tsx and .jsx files). reactHooks.configs.flat.recommended, // Jest test lint rules. (.ts and .js test files). jest.configs['flat/recommended'], // TypeScript syntax and basic correctness; does not use type information (.ts, .tsx, .mts files). tslint.configs.recommended, // Stricter TypeScript rules using the type checker { ...love, files: ['**/*.{ts,tsx,mts}'], languageOptions: { ...love.languageOptions, parserOptions: { project: './tsconfig-lint.json', }, }, }, // Enforce license header in file (all files). Overlaps with PRESUBMIT. { plugins: { licenses, }, rules: { 'licenses/header': [ 2, { tryUseCreatedYear: true, comment: { allow: 'both', prefer: 'line', }, header: [ 'Copyright (c) {YEAR} The Brave Authors. All rights reserved.', 'This Source Code Form is subject to the terms of the Mozilla Public', 'License, v. 2.0. If a copy of the MPL was not distributed with this file,', 'You can obtain one at https://mozilla.org/MPL/2.0/.', ], altHeaders: [ [ 'Copyright (c) {YEAR} The Brave Authors. All rights reserved.', '* This Source Code Form is subject to the terms of the Mozilla Public', '* License, v. 2.0. If a copy of the MPL was not distributed with this file,', '* You can obtain one at https://mozilla.org/MPL/2.0/.', ], [ 'This Source Code Form is subject to the terms of the Mozilla Public', '* License, v. 2.0. If a copy of the MPL was not distributed with this file,', '* You can obtain one at https://mozilla.org/MPL/2.0/.', ], [ 'Copyright (c) {YEAR} The Brave Authors. All rights reserved.', 'This Source Code Form is subject to the terms of the Mozilla Public', 'License, v. 2.0. If a copy of the MPL was not distributed with this file,', 'you can obtain one at https://mozilla.org/MPL/2.0/.', ], ], }, ], }, }, globalIgnores([ '.storybook/*', 'browser/*', 'ui/webui/resources/*', '**/*.d.ts', 'tools/chromium_src/lit_mangler/*.ts', // External or vendored code; not maintained in this repo 'vendor/', 'third_party/', 'tools/crates/vendor/', // Not purely JavaScript, contains `