Skip to content

Commit

Permalink
build: lint package.json files (#1031)
Browse files Browse the repository at this point in the history
* build: lint `package.json` files

* build: configure lint-staged for json files

* chore: document why `*.json` is needed
  • Loading branch information
davidlj95 authored Nov 12, 2024
1 parent 78a0cf9 commit 69edb48
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 5 deletions.
14 changes: 13 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// 👇 Added `coverage/**/*` to be able to run 'eslint .' successfully
// When upgrading to v9, can include .gitignore here. In v8, you need to add a CLI flag
// Given 'eslint .' is not something ran often, it's good enough as ienough as is
"ignorePatterns": ["projects/**/*", "coverage/**/*"],
// Removing `projects/**/*` to allow using `eslint .` to lint everything.
"ignorePatterns": ["coverage/**/*", "!.*.json"],
"parserOptions": {
"ecmaVersion": 9 // for jest.config.js files on IntelliJ
},
Expand Down Expand Up @@ -47,6 +48,17 @@
{
"files": ["*.cy.ts"],
"extends": ["plugin:cypress/recommended"]
},
{
//👇 `*.json` is needed so that when `lint-staged` sends any kind of JSON file,
// ESLint doesn't complain about them. However, just `package.json` files are linted.
"files": ["*.json"],
"plugins": ["json-files"],
"rules": {
"json-files/require-unique-dependency-names": "error",
"json-files/ensure-repository-directory": "error",
"json-files/restrict-ranges": ["error", { "versionHint": "pin" }]
}
}
]
}
4 changes: 2 additions & 2 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"!(*.ts)": ["pnpm run format"],
"*.ts": ["pnpm run lint:code:raw --fix", "pnpm run format"],
"!(*.{json,ts})": ["pnpm run format"],
"*.{json,ts}": ["pnpm run lint:code:raw --fix", "pnpm run format"],
".github/**/*.{yml,yaml}": ["pnpm run lint:gh-actions"]
}
3 changes: 1 addition & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
"builder": "@angular-eslint/builder:lint",
"options": {
"lintFilePatterns": [
"projects/ngx-meta/src/**/*.ts",
"projects/ngx-meta/src/**/*.html",
"projects/ngx-meta/src/**/*.{ts,html}",
"projects/ngx-meta/e2e/**/*.ts",
"projects/ngx-meta/example-apps/**/*.ts",
"projects/ngx-meta/schematics/**/*.ts"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"eslint-plugin-cypress": "3.6.0",
"eslint-plugin-jasmine": "4.2.2",
"eslint-plugin-jest": "28.8.3",
"eslint-plugin-json-files": "4.4.1",
"husky": "9.1.6",
"jasmine-core": "5.4.0",
"jest": "29.7.0",
Expand Down
115 changes: 115 additions & 0 deletions pnpm-lock.yaml

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

4 changes: 4 additions & 0 deletions projects/ngx-meta/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../.eslintrc.json",
"ignorePatterns": ["dist/**/*", "out/**/*"]
}
4 changes: 4 additions & 0 deletions projects/ngx-meta/docs/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../../.eslintrc.json",
"ignorePatterns": ["content/fonts/**/*"]
}
8 changes: 8 additions & 0 deletions projects/ngx-meta/src/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"files": ["*.spec.ts"],
"extends": ["plugin:jasmine/recommended"],
"plugins": ["jasmine"]
},
{
"files": ["package.json"],
"plugins": ["json-files"],
"rules": {
"json-files/require-license": "error",
"json-files/restrict-ranges": ["error", { "versionHint": "caret" }]
}
}
]
}

0 comments on commit 69edb48

Please sign in to comment.