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, { declareConfig } from "eslint-config-cobaltt7"; export default declareConfig({ files: ["**/*.ts"] }, ...cobaltConfigs, { languageOptions: { parserOptions: { projectService: true, tsconfigRootDir: path.dirname(fileURLToPath(import.meta.url)), }, }, });
-
Add
ignores
globs to omit certain files or folders from being linted, for example:@@ -5,6 +5,7 @@ export default declareConfig( { files: ["**/*.ts"] }, + { ignores: ["dist"] }, ...cobaltConfigs, { languageOptions: {
Make sure to put
ignores
in its own object and 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 globals. 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.