Skip to content

Commit 23fd76c

Browse files
committed
Initial commit
0 parents  commit 23fd76c

29 files changed

+6710
-0
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
!.eslintrc.js
2+
/coverage/
3+
/dist/

.eslintrc.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/** @type import("eslint").Linter.BaseConfig<import("eslint").Linter.RulesRecord> */
2+
module.exports = {
3+
env: { node: true },
4+
extends: [
5+
"eslint:recommended",
6+
"plugin:import/recommended",
7+
"plugin:promise/recommended",
8+
"plugin:@typescript-eslint/eslint-recommended",
9+
"plugin:@typescript-eslint/recommended",
10+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
11+
"plugin:import/typescript",
12+
"prettier/@typescript-eslint",
13+
"plugin:prettier/recommended",
14+
],
15+
noInlineConfig: true,
16+
parser: "@typescript-eslint/parser",
17+
parserOptions: {
18+
project: [
19+
`${__dirname}/tsconfig.json`,
20+
`${__dirname}/tsconfig.eslint.json`,
21+
],
22+
},
23+
reportUnusedDisableDirectives: true,
24+
root: true,
25+
rules: {
26+
curly: ["error", "all"],
27+
eqeqeq: "error",
28+
29+
/**
30+
* TypeScript provides equivalent checks, so we turn them off
31+
* @see https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md#eslint-plugin-import
32+
*/
33+
"import/default": "off",
34+
"import/named": "off",
35+
"import/namespace": "off",
36+
"import/no-named-as-default-member": "off",
37+
},
38+
overrides: [
39+
{
40+
files: ["lint-staged.config.js"],
41+
42+
rules: {
43+
"@typescript-eslint/no-var-requires": "off",
44+
},
45+
},
46+
],
47+
};

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.tsbuildinfo
2+
/coverage/
3+
/dist/

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__fixtures__
2+
/coverage/
3+
/dist/

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Patrick Eriksson
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# eslint-plugin-diff
2+
3+
Run ESLint on your changes only
4+
5+
## What problem does it solve?
6+
7+
Introducing new ESLint rules (or updating 3rd party configs) in a large codebase can be tedious. This plugin allows your team to ease into new rules by only linting all new/modified code, eventually migrating to the new/updated rules.
8+
9+
## Installation
10+
11+
```sh
12+
$ yarn add -D eslint-plugin-diff
13+
```
14+
15+
## Usage
16+
17+
It's recommended to use [`"plugin:diff/staged"` (see config)](#config-staged-diff-staged-changes-only).
18+
19+
### Config `staged` — Diff staged changes only
20+
21+
> **Useful for pre-commit hooks, e.g. when running ESLint with lint-staged**
22+
23+
Extend your config in **`.eslintrc`**:
24+
25+
```json
26+
{
27+
"extends": ["plugin:diff/staged"]
28+
}
29+
```
30+
31+
_Equivalent to `git diff HEAD --staged`_
32+
33+
### Config `diff` — Diff all changes since HEAD (staged and unstaged)
34+
35+
Extend your config in **`.eslintrc`**:
36+
37+
```json
38+
{
39+
"extends": ["plugin:diff/diff"]
40+
}
41+
```
42+
43+
_Equivalent to `git diff HEAD`_

husky.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
hooks: {
3+
"pre-commit": "lint-staged",
4+
},
5+
};

jest.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
collectCoverageFrom: ["src/**/*.ts"],
3+
coverageThreshold: {
4+
global: {
5+
branches: 80,
6+
functions: 80,
7+
lines: 80,
8+
statements: -10,
9+
},
10+
},
11+
preset: "ts-jest",
12+
testEnvironment: "node",
13+
modulePathIgnorePatterns: ["<rootDir>/dist/"],
14+
};

lint-staged.config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { CLIEngine } = require("eslint");
2+
3+
const cli = new CLIEngine({});
4+
5+
/**
6+
* @param {string[]} files
7+
*/
8+
const eslintFiles = (files) =>
9+
files.filter((file) => !cli.isPathIgnored(file)).join(" ");
10+
11+
module.exports = {
12+
"*.{html,json,md,yaml,yml}": ["prettier --write"],
13+
"*.{js,ts}": [
14+
() => "yarn run typecheck",
15+
"jest --bail --findRelatedTests",
16+
/**
17+
* @param {string[]} files
18+
*/
19+
(files) => `eslint --fix ${eslintFiles(files)}`,
20+
],
21+
};

package.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"name": "eslint-plugin-diff",
3+
"version": "0.0.0",
4+
"description": "Run ESLint on your changes only",
5+
"keywords": [
6+
"eslint",
7+
"eslintplugin",
8+
"eslint-plugin",
9+
"diff"
10+
],
11+
"homepage": "https://github.com/paleite/eslint-plugin-diff#readme",
12+
"bugs": {
13+
"url": "https://github.com/paleite/eslint-plugin-diff/issues"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "git+https://github.com/paleite/eslint-plugin-diff.git"
18+
},
19+
"license": "MIT",
20+
"author": "Patrick Eriksson <[email protected]> (https://github.com/paleite)",
21+
"main": "dist/index.js",
22+
"files": [
23+
"/dist/"
24+
],
25+
"scripts": {
26+
"build": "tsc --build tsconfig.build.json",
27+
"clean": "tsc --build tsconfig.build.json --clean",
28+
"format": "prettier --write .",
29+
"lint": "eslint --cache --ext .js,.ts --fix --format codeframe .",
30+
"release": "np",
31+
"test": "jest",
32+
"typecheck": "tsc --project tsconfig.json"
33+
},
34+
"devDependencies": {
35+
"@types/eslint": "^7.2.0",
36+
"@types/jest": "^26.0.8",
37+
"@types/node": "^14.0.27",
38+
"@typescript-eslint/eslint-plugin": "^3.8.0",
39+
"@typescript-eslint/parser": "^3.8.0",
40+
"eslint": "^7.0.0",
41+
"eslint-config-prettier": "^6.11.0",
42+
"eslint-plugin-import": "^2.22.0",
43+
"eslint-plugin-prettier": "^3.1.4",
44+
"eslint-plugin-promise": "^4.2.1",
45+
"husky": "^4.2.5",
46+
"jest": "^26.2.2",
47+
"lint-staged": "^10.2.11",
48+
"np": "^6.3.2",
49+
"prettier": "^2.0.5",
50+
"ts-jest": "^26.1.4",
51+
"typescript": "^3.9.7"
52+
},
53+
"peerDependencies": {
54+
"eslint": ">=7.0.0"
55+
},
56+
"engines": {
57+
"node": ">=12.0.0"
58+
}
59+
}

0 commit comments

Comments
 (0)