Skip to content

Commit f6151ed

Browse files
author
Paul Marbach
committed
feat: use package attributes to determine lint preset
By checking the package that called web-scripts or eslint-config, we can determine whether we should check for React or TypeScript stuff or not. fix #56
1 parent a339c39 commit f6151ed

24 files changed

+295
-35
lines changed

packages/create-web-scripts-library/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"fs-extra": "^7.0.1"
4141
},
4242
"devDependencies": {
43-
"@spotify/web-scripts": "^2.0.0",
4443
"@types/fs-extra": "^7.0.0",
4544
"tempy": "^0.3.0"
4645
},

packages/eslint-config/index.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1+
const { hasConfig } = require('@spotify/web-scripts-utils');
2+
3+
const hasReact = hasConfig([
4+
{ type: 'dependency', dependency: 'react' },
5+
{ type: 'dependency', dependency: 'react', dependencyType: 'peer' },
6+
]);
7+
const hasTypescript = hasConfig([
8+
{ type: 'dependency', dependency: 'typescript' },
9+
{ type: 'dependency', dependency: 'typescript', dependencyType: 'dev' },
10+
{ type: 'file', pattern: 'tsconfig.json' },
11+
]);
12+
113
module.exports = {
214
extends: [
315
'@spotify/eslint-config-base',
4-
'@spotify/eslint-config-react',
5-
'@spotify/eslint-config-typescript',
16+
hasReact ? '@spotify/eslint-config-react' : null,
17+
hasTypescript ? '@spotify/eslint-config-typescript' : null,
618
'prettier',
7-
'prettier/react',
8-
'prettier/@typescript-eslint',
9-
],
19+
hasReact ? 'prettier/react' : null,
20+
hasTypescript ? 'prettier/@typescript-eslint' : null,
21+
].filter(s => !!s),
1022
parser: '@typescript-eslint/parser',
1123
env: {
1224
jest: true,

packages/eslint-config/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@spotify/eslint-config-base": "^2.0.0",
2121
"@spotify/eslint-config-react": "^2.0.0",
2222
"@spotify/eslint-config-typescript": "^2.0.0",
23+
"@spotify/web-scripts-utils": "^2.0.0",
2324
"@typescript-eslint/eslint-plugin": "^1.11.0",
2425
"@typescript-eslint/parser": "^1.11.0",
2526
"eslint-config-prettier": "^6.0.0",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__fixtures__
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# `web-scripts-utils`
2+
3+
> TODO: description
4+
5+
## Usage
6+
7+
```
8+
const webScriptsUtils = require('web-scripts-utils');
9+
10+
// TODO: DEMONSTRATE API
11+
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/*.ts
2+
**/*.tsx
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "some-dummy-project",
3+
"jest": {
4+
"collectCoverageFrom": "src/**/*.ts"
5+
},
6+
"dependencies": {
7+
"react": "*"
8+
},
9+
"devDependencies": {
10+
"@testing-library/react": "*"
11+
},
12+
"peerDependencies": {
13+
"styled-components": "*"
14+
}
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const a = () => '';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "@spotify/tsconfig/tsconfig.lib.json",
3+
"include": ["src"]
4+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "@spotify/web-scripts-utils",
3+
"version": "2.0.0",
4+
"private": true,
5+
"description": "Private package which contains re-used utils within web-scripts projects",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/spotify/web-scripts.git"
9+
},
10+
"main": "cjs/index.js",
11+
"module": "esm/index.js",
12+
"types": "types",
13+
"files": [
14+
"cjs",
15+
"esm",
16+
"types"
17+
],
18+
"scripts": {
19+
"clean": "rm -rf cjs esm types",
20+
"build": "web-scripts build",
21+
"test": "web-scripts test",
22+
"lint": "web-scripts lint",
23+
"format": "web-scripts format",
24+
"bootstrap": "$npm_execpath run clean && tsc --allowJs --outDir cjs --noEmit false --module CommonJS && tsc --declaration --isolatedModules false --outDir types --emitDeclarationOnly --noEmit false",
25+
"prepublishOnly": "$npm_execpath run build",
26+
"prepare": "$npm_execpath run build"
27+
},
28+
"dependencies": {
29+
"glob": "^7.1.4",
30+
"read-pkg-up": "^6.0.0"
31+
},
32+
"devDependencies": {
33+
"@spotify/tsconfig": "^2.0.0"
34+
},
35+
"engines": {
36+
"node": ">= 10"
37+
}
38+
}

0 commit comments

Comments
 (0)