Skip to content

Commit

Permalink
feat(eslint-config)!: split config packages (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous authored Dec 3, 2024
1 parent ff06fba commit e7d663f
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 76 deletions.
22 changes: 22 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,26 @@ module.exports = {
env: {
node: true,
},
overrides: [
{
files: [
'packages/eslint-config/**/*.js',
'packages/eslint-config-svelte/**/*.js',
],
parserOptions: {
sourceType: 'script',
},
env: {
commonjs: true,
},
rules: {
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-var-requires': 'off',
'unicorn/prefer-module': 'off',
},
},
],
};
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@ Shared configuration for JavaScript and TypeScript tools.

## Libraries

| Tool | NPM Module | Version |
| ----------------------------- | --------------------------------- | ----------------------------------------- |
| [ESLint][eslint docs] | `@viamrobotics/eslint-config` | [![eslint version][]][eslint npm] |
| [Prettier][prettier docs] | `@viamrobotics/prettier-config` | [![prettier version][]][prettier npm] |
| [TypeScript][typescript docs] | `@viamrobotics/typescript-config` | [![typescript version][]][typescript npm] |
| Tool | NPM Module | Version |
| ----------------------------------------- | -------------------------------------- | --------------------------------------------------- |
| [ESLint][eslint docs] | `@viamrobotics/eslint-config` | [![eslint version][]][eslint npm] |
| [ESLint + Svelte][eslint-svelte docs] | `@viamrobotics/eslint-config-svelte` | [![eslint-svelte version][]][eslint-svelte npm] |
| [Prettier][prettier docs] | `@viamrobotics/prettier-config` | [![prettier version][]][prettier npm] |
| [Prettier + Svelte][prettier-svelte docs] | `@viamrobotics/prettier-config-svelte` | [![prettier-svelte version][]][prettier-svelte npm] |
| [TypeScript][typescript docs] | `@viamrobotics/typescript-config` | [![typescript version][]][typescript npm] |

[eslint docs]: ./packages/eslint-config
[eslint npm]: https://www.npmjs.com/package/@viamrobotics/eslint-config
[eslint version]: https://img.shields.io/npm/v/@viamrobotics/eslint-config?style=flat-square
[eslint-svelte docs]: ./packages/eslint-config-svelte
[eslint-svelte npm]: https://www.npmjs.com/package/@viamrobotics/eslint-config-svelte
[eslint-svelte version]: https://img.shields.io/npm/v/@viamrobotics/eslint-config-svelte?style=flat-square
[prettier docs]: ./packages/prettier-config
[prettier npm]: https://www.npmjs.com/package/@viamrobotics/prettier-config
[prettier version]: https://img.shields.io/npm/v/@viamrobotics/prettier-config?style=flat-square
[prettier-svelte docs]: ./packages/prettier-config-svelte
[prettier-svelte npm]: https://www.npmjs.com/package/@viamrobotics/prettier-config-svelte
[prettier-svelte version]: https://img.shields.io/npm/v/@viamrobotics/prettier-config-svelte?style=flat-square
[typescript docs]: ./packages/typescript-config
[typescript npm]: https://www.npmjs.com/package/@viamrobotics/typescript-config
[typescript version]: https://img.shields.io/npm/v/@viamrobotics/typescript-config?style=flat-square
Expand Down
2 changes: 2 additions & 0 deletions packages/eslint-config-svelte/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tsconfig.json
*.tsbuildinfo
45 changes: 45 additions & 0 deletions packages/eslint-config-svelte/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Viam's ESLint Config for Svelte

This module contains [Viam][]'s shared [ESLint][] configurations for ESLint v8 in [Svelte][] projects.

[viam]: https://www.viam.com/
[eslint]: https://eslint.org/
[svelte]: https://svelte.dev/

## Base config

Extend the [config](./eslint-config-svelte.js) in `.eslintrc.cjs`.

```shell
pnpm add --save-dev \
eslint@^8.56.0 \
@viamrobotics/eslint-config-svelte \
@typescript-eslint/parser \
@typescript-eslint/eslint-plugin \
eslint-config-prettier \
eslint-plugin-jest-dom \
eslint-plugin-simple-import-sort \
eslint-plugin-svelte \
eslint-plugin-tailwindcss \
eslint-plugin-testing-library \
eslint-plugin-unicorn \
eslint-plugin-vitest
```

```js
// .eslintrc.cjs
'use strict';

module.exports = {
root: true,
extends: ['@viamrobotics/eslint-config-svelte'],
parserOptions: {
tsconfigRootDir: __dirname,
projectService: true,
},
};
```

## Non-Svelte projects

See [@viamrobotics/eslint-config](../eslint-config/)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const baseConfig = require('./base.cjs');
const baseConfig = require('@viamrobotics/eslint-config');

module.exports = {
...baseConfig,
Expand All @@ -11,6 +11,12 @@ module.exports = {
'plugin:svelte/prettier',
],
settings: {
svelte: {
ignoreWarnings: [
'@typescript-eslint/no-unsafe-assignment',
'@typescript-eslint/no-unsafe-member-access',
],
},
tailwindcss: {
callees: ['classnames', 'cx'],
classRegex: '^(?:class|cx)$',
Expand All @@ -29,6 +35,8 @@ module.exports = {
parser: '@typescript-eslint/parser',
},
rules: {
// Redundant with `svelte-check` and build
'svelte/valid-compile': 'off',
// Allows us to set option props to `undefined` by default
'no-undef-init': 'off',
},
Expand Down
46 changes: 46 additions & 0 deletions packages/eslint-config-svelte/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@viamrobotics/eslint-config-svelte",
"publishConfig": {
"access": "public"
},
"version": "0.8.0",
"description": "ESLint configuration for Svelte projects at Viam.",
"type": "commonjs",
"main": "./eslint-config-svelte.js",
"types": "./dist/eslint-config-svelte.d.ts",
"exports": {
".": {
"types": "./dist/eslint-config-svelte.d.ts",
"default": "./eslint-config-svelte.js"
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/viamrobotics/js-config.git",
"directory": "packages/eslint-config-svelte"
},
"keywords": [
"eslint",
"eslintconfig",
"svelte"
],
"license": "Apache-2.0",
"dependencies": {
"@viamrobotics/eslint-config": "workspace:*"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": ">=6 <9",
"@typescript-eslint/parser": ">=6 <9",
"eslint": ">=8 <9",
"eslint-config-prettier": ">=9 <10",
"eslint-plugin-jest-dom": ">=5 <6",
"eslint-plugin-simple-import-sort": ">=12 <13",
"eslint-plugin-svelte": ">=2 <3",
"eslint-plugin-tailwindcss": ">=3 <4",
"eslint-plugin-testing-library": ">=6 <8",
"eslint-plugin-unicorn": ">=47 <57",
"eslint-plugin-vitest": ">=0.5 <0.6",
"typescript": ">=5 <6",
"vitest": "*"
}
}
12 changes: 12 additions & 0 deletions packages/eslint-config-svelte/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@viamrobotics/typescript-config/base.json",
"compilerOptions": {
"types": ["node"],
"composite": true,
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "dist"
},
"references": [{ "path": "../eslint-config" }],
"include": ["*.js"]
}
2 changes: 2 additions & 0 deletions packages/eslint-config/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tsconfig.json
*.tsbuildinfo
40 changes: 7 additions & 33 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Shared ESLint Config for Viam
# Viam's ESLint Config

This module contains [Viam][]'s shared [ESLint][] configurations for ESLint v8.

Expand All @@ -7,15 +7,16 @@ This module contains [Viam][]'s shared [ESLint][] configurations for ESLint v8.

## Base config

Use the [base config](./base.cjs) for vanilla JavaScript / TypeScript projects. Be sure to add your `tsconfig.json` files to `parserOptions.project` and `settings['import/resolver'].typescript.project`.
Extend the [config](./eslint-config.js) in `.eslintrc.cjs`.

```shell
pnpm add --save-dev \
eslint@^8.56.0 \
@viamrobotics/eslint-config \
@typescript-eslint/parser \
@typescript-eslint/eslint-plugin \
eslint \
eslint-config-prettier \
eslint-plugin-simple-import-sort \
eslint-plugin-unicorn \
eslint-plugin-vitest
```
Expand All @@ -28,39 +29,12 @@ module.exports = {
root: true,
extends: ['@viamrobotics/eslint-config'],
parserOptions: {
project: ['./tsconfig.json'],
tsconfigRootDir: __dirname,
projectService: true,
},
};
```

## Svelte config

Use the [Svelte config](./svelte.cjs) for Svelte projects.

```shell
pnpm add --save-dev \
@viamrobotics/eslint-config \
@typescript-eslint/parser \
@typescript-eslint/eslint-plugin \
eslint \
eslint-config-prettier \
eslint-plugin-jest-dom \
eslint-plugin-svelte \
eslint-plugin-tailwindcss \
eslint-plugin-testing-library \
eslint-plugin-unicorn \
eslint-plugin-vitest
```

```js
// .eslintrc.cjs
'use strict';

module.exports = {
root: true,
extends: ['@viamrobotics/eslint-config/svelte'],
parserOptions: {
project: ['./tsconfig.json'],
},
};
```
See [@viamrobotics/eslint-config-svelte](../eslint-config-svelte/)
File renamed without changes.
48 changes: 12 additions & 36 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,15 @@
"access": "public",
"provenance": true
},
"version": "0.7.1",
"description": "Common ESLint configuration for Viam projects.",
"files": [
"**/*",
"!tsconfig.json"
],
"types": "dist/base.d.cts",
"typesVersions": {
"*": {
"svelte": [
"dist/svelte.d.cts"
]
}
},
"version": "0.8.0",
"description": "ESLint configuration for projects at Viam.",
"type": "commonjs",
"main": "./eslint-config.js",
"types": "./dist/eslint-config.d.ts",
"exports": {
".": {
"types": "./dist/base.d.cts",
"default": "./base.cjs"
},
"./svelte": {
"types": "./dist/svelte.d.cts",
"default": "./svelte.cjs"
"types": "./dist/eslint-config.d.ts",
"default": "./eslint-config.js"
}
},
"repository": {
Expand All @@ -43,28 +30,17 @@
"@typescript-eslint/parser": ">=6 <9",
"eslint": ">=8 <9",
"eslint-config-prettier": ">=9 <10",
"eslint-plugin-jest-dom": ">=5 <6",
"eslint-plugin-simple-import-sort": ">=12 <13",
"eslint-plugin-svelte": ">=2 <3",
"eslint-plugin-tailwindcss": ">=3 <4",
"eslint-plugin-testing-library": ">=6 <8",
"eslint-plugin-unicorn": ">=47 <57",
"eslint-plugin-vitest": ">=0.5 <0.6"
"eslint-plugin-vitest": ">=0.5 <0.6",
"typescript": ">=5 <6",
"vitest": "*"
},
"peerDependenciesMeta": {
"eslint-plugin-jest-dom": {
"optional": true
},
"eslint-plugin-svelte": {
"optional": true
},
"eslint-plugin-tailwindcss": {
"optional": true
},
"eslint-plugin-testing-library": {
"eslint-plugin-vitest": {
"optional": true
},
"eslint-plugin-vitest": {
"vitest": {
"optional": true
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"emitDeclarationOnly": true,
"outDir": "dist"
},
"include": ["**/*.cjs"]
"include": ["*.js"]
}
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/peers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface PackageJSON {
const repo = path.join(url.fileURLToPath(import.meta.url), '../..');
const packages = [
'eslint-config',
'eslint-config-svelte',
'prettier-config',
'prettier-config-svelte',
'typescript-config',
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"references": [
{ "path": "./packages/eslint-config" },
{ "path": "./packages/eslint-config-svelte" },
{ "path": "./packages/prettier-config" },
{ "path": "./packages/prettier-config-svelte" }
],
Expand Down

0 comments on commit e7d663f

Please sign in to comment.