My ESLint style guide
-
Note that this style guide only works for TypeScript projects, so ensure you have TypeScript installed and configured prior to setting up ESLint.
-
Install the config by running:
npm install eslint-config-cobaltt7 eslint --save-dev --save-exact
-
Add the following to your
package.json
:"scripts": { "lint": "eslint" }
-
Create an eslint.config.js file with the following content:
import path from "node:path"; import { fileURLToPath } from "node:url"; import cobaltConfigs from "eslint-config-cobaltt7"; import { defineConfig } from "eslint/config"; export default defineConfig([ { files: ["./**/*.ts"] }, ...cobaltConfigs, { languageOptions: { parserOptions: { projectService: true, tsconfigRootDir: path.dirname(fileURLToPath(import.meta.url)), }, }, }, ]);
-
Add
globalIgnores
globs to omit certain files or folders from being linted, for example:@@ -1,10 +1,12 @@ import path from "node:path"; import { fileURLToPath } from "node:url"; import cobaltConfigs, { declareConfig } from "eslint-config-cobaltt7"; -import { defineConfig } from "eslint/config"; +import { defineConfig, globalIgnores } from "eslint/configs"; export default defineConfig([ { files: ["./**/*.ts"] }, + globalIgnores(["./dist"]), ...cobaltConfigs, { languageOptions: {
Make sure to put
globalIgnores
in the position indicated. -
Edit project-specific configuration, i.e.
languageOptions
,rules
, and etcetera. Put all configuration in or after the last object containinglanguageOptions
. Theglobals
package is re-exported ineslint-config-cobaltt7
, so it is unneccessary to reinstall it to modify global variables. Simply import it like so:import { globals } from "eslint-config-cobaltt7";
-
To lint your code, simply run:
node --run lint
Congrats!
You've successfully integrated ESLint into your project with eslint-config-cobaltt7
!
The following configs are exported from this package independently:
import { configs } from "eslint-config-cobaltt7";
configs.global;
configs.configs;
configs.declarations;
configs.tests;
Please note that, with the exeption of global
, all of these configs include files
overrides that may need to be overridden for the config to behave as expected.