diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..7cdcb23 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,5 @@ +const config = require('./src/config'); + +module.exports = { + ...config, +}; diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index e2eb7f2..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": ["eslint:recommended", "plugin:prettier/recommended"], - "env": { "es6": true, "node": true }, - "rules": { - "no-console": ["error", { "allow": ["warn", "error"] }] - }, - "ignorePatterns": ["node_modules"] -} diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b87971..cb119f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,17 +5,22 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [v0.1.3] - 2024-01-19 +## [v0.2.0] - 2024-01-23 -### Fixed +### Changed -- changelog version links -- `typescript-eslint` plugin not being declared as dependency +- Default export is now JavaScript eslint config. ### Added +- Different configuration files to JavaScript and TypeScript. - `eslint-plugin-import` as dependency +### Fixed + +- changelog version links +- `typescript-eslint` plugin not being declared as dependency + ## [v0.1.2] - 2024-01-17 ### Fixed @@ -33,7 +38,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - First release -[v0.1.3]: https://www.npmjs.com/package/@dipcode/eslint-config/v/0.1.3 +[v0.2.0]: https://www.npmjs.com/package/@dipcode/eslint-config/v/0.2.0 [v0.1.2]: https://www.npmjs.com/package/@dipcode/eslint-config/v/0.1.2 [v0.1.1]: https://www.npmjs.com/package/@dipcode/eslint-config/v/0.1.1 [v0.1.0]: https://www.npmjs.com/package/@dipcode/eslint-config/v/0.1.0 diff --git a/README.md b/README.md index 821cf48..a929820 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,35 @@ The package provides Dipcode's `.eslintrc` as an extensible shared config. -1. Run `npm install --save-dev @dipcode/eslint-config` -2. Add `"extends": "@dipcode/eslint-config"` to your `.eslintrc.json` +Install the config + +```sh +npm install --save-dev @dipcode/eslint-config +``` + +Then configure eslint to use the configuration. + +### For JavaScript projects + +`.eslintrc.json` + +```json +{ + "root": true, + "extends": "@dipcode/eslint-config" +} +``` + +### For TypeScript projects + +`.eslintrc.json` + +```json +{ + "root": true, + "extends": "@dipcode/eslint-config/typescript" +} +``` ## Links diff --git a/package-lock.json b/package-lock.json index 0aa18ca..669c60e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dipcode/eslint-config", - "version": "0.1.3", + "version": "0.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dipcode/eslint-config", - "version": "0.1.3", + "version": "0.2.0", "license": "MIT", "dependencies": { "@typescript-eslint/eslint-plugin": "^6.19.0", @@ -20,7 +20,7 @@ "eslint-plugin-simple-import-sort": "^10.0.0" }, "devDependencies": { - "@dipcode/prettier-config": "^0.1.0", + "@dipcode/prettier-config": "0.1.0", "husky": "8.0.3", "lint-staged": "15.2.0" }, diff --git a/package.json b/package.json index b8c7a87..2731eb1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dipcode/eslint-config", - "version": "0.1.3", + "version": "0.2.0", "description": "Shareable ESLint config for Dipcode.", "main": "./src/config.js", "scripts": { @@ -28,7 +28,14 @@ "url": "https://github.com/dipcode-software/eslint-config-dipcode/issues" }, "homepage": "https://github.com/dipcode-software/eslint-config-dipcode#readme", - "exports": "./src/config.js", + "exports": { + ".": "./src/config.js", + "./typescript": "./src/typescript.js" + }, + "files": [ + "src/config.js", + "src/typescript.js" + ], "devDependencies": { "@dipcode/prettier-config": "0.1.0", "husky": "8.0.3", diff --git a/src/config.js b/src/config.js index 97b4d3c..64c4024 100644 --- a/src/config.js +++ b/src/config.js @@ -1,53 +1,26 @@ 'use strict'; module.exports = { - env: { - browser: true, - es2022: true, - }, + env: { browser: true, es2022: true, commonjs: true }, extends: [ 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:jsdoc/recommended-typescript-error', 'plugin:import/recommended', - 'plugin:import/typescript', 'plugin:promise/recommended', // This must be the last 'plugin:prettier/recommended', ], - plugins: ['@typescript-eslint', 'simple-import-sort', 'jsdoc'], - parser: '@typescript-eslint/parser', - parserOptions: { project: 'tsconfig.json', sourceType: 'module' }, + plugins: ['simple-import-sort', 'jsdoc'], rules: { - '@typescript-eslint/ban-ts-comment': ['error', { 'ts-expect-error': 'allow-with-description' }], + 'camelcase': 'error', 'simple-import-sort/imports': 'error', 'simple-import-sort/exports': 'error', 'no-console': ['error', { allow: ['warn', 'error'] }], - '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }], - 'import/extensions': [ - 2, - 'always', - { - ignorePackages: true, - pattern: { - js: 'never', - ts: 'never', - tsx: 'never', - }, - }, - ], + 'import/extensions': [2, 'always', { ignorePackages: true, pattern: { js: 'never' } }], }, ignorePatterns: ['node_modules'], settings: { - 'import/parsers': { - '@typescript-eslint/parser': ['.ts', '.tsx', '.d.ts'], - }, - 'import/resolver': { - node: { - extensions: ['.js', '.json', '.ts', '.tsx', '.d.ts'], - }, - }, - 'import/extensions': ['.js', '.mjs', '.ts', '.tsx', '.d.ts'], + 'import/resolver': { node: { extensions: ['.js', '.json'] } }, + 'import/extensions': ['.js', '.mjs'], 'import/external-module-folders': ['node_modules', 'node_modules/@types'], }, overrides: [{ files: ['*.ts', '*.tsx'], rules: { 'import/named': 'off', 'import/no-unresolved': 'off' } }], diff --git a/src/typescript.js b/src/typescript.js new file mode 100644 index 0000000..2b5ab9a --- /dev/null +++ b/src/typescript.js @@ -0,0 +1,35 @@ +'use strict'; + +const base = require('./config'); + +module.exports = { + env: { ...base.env }, + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:jsdoc/recommended-typescript-error', + 'plugin:import/recommended', + 'plugin:import/typescript', + 'plugin:promise/recommended', + // This must be the last line + 'plugin:prettier/recommended', + ], + plugins: ['@typescript-eslint', ...base.plugins], + parser: '@typescript-eslint/parser', + parserOptions: { project: './tsconfig.json', sourceType: 'module' }, + rules: { + ...base.rules, + '@typescript-eslint/ban-ts-comment': ['error', { 'ts-expect-error': 'allow-with-description' }], + '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }], + 'import/extensions': [2, 'always', { ignorePackages: true, pattern: { js: 'never', ts: 'never', tsx: 'never' } }], + }, + settings: { + ...base.settings, + 'import/parsers': { '@typescript-eslint/parser': ['.ts', '.tsx', '.d.ts'] }, + 'import/resolver': { + node: { extensions: [...base.settings['import/resolver'].node.extensions, '.ts', '.tsx', '.d.ts'] }, + }, + 'import/extensions': [...base.settings['import/extensions'], '.ts', '.tsx', '.d.ts'], + }, + overrides: [{ files: ['*.ts', '*.tsx'], rules: { 'import/named': 'off', 'import/no-unresolved': 'off' } }], +};