Skip to content

Commit 4695b3c

Browse files
committed
Initial commit
0 parents  commit 4695b3c

13 files changed

+3615
-0
lines changed

.github/workflows/build.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: build
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
strategy:
10+
matrix:
11+
node-version: [14.x]
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Use Node.js ${{ matrix.node-version }}
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: ${{ matrix.node-version }}
19+
- name: Install dependencies
20+
run: yarn --frozen-lockfile
21+
- name: Format check
22+
run: yarn format:check
23+
- name: Unit Testing
24+
run: yarn test
25+
env:
26+
CI: true

.gitignore

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
2+
# Created by https://www.gitignore.io/api/node
3+
# Edit at https://www.gitignore.io/?templates=node
4+
5+
### Node ###
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# Optional npm cache directory
48+
.npm
49+
50+
# Optional eslint cache
51+
.eslintcache
52+
53+
# Optional REPL history
54+
.node_repl_history
55+
56+
# Output of 'npm pack'
57+
*.tgz
58+
59+
# Yarn Integrity file
60+
.yarn-integrity
61+
62+
# dotenv environment variables file
63+
.env
64+
.env.test
65+
66+
# parcel-bundler cache (https://parceljs.org/)
67+
.cache
68+
69+
# next.js build output
70+
.next
71+
72+
# nuxt.js build output
73+
.nuxt
74+
75+
# vuepress build output
76+
.vuepress/dist
77+
78+
# Serverless directories
79+
.serverless/
80+
81+
# FuseBox cache
82+
.fusebox/
83+
84+
# DynamoDB Local files
85+
.dynamodb/
86+
87+
# End of https://www.gitignore.io/api/node
88+
89+
lib/
90+
.DS_Store
91+
.idea/

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
lib/
2+
__snapshots__/
3+
coverage/
4+
node_modules/
5+
*.png

.prettierrc.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
trailingComma: all
2+
tabWidth: 2
3+
semi: true
4+
singleQuote: false
5+
bracketSpacing: true
6+
printWidth: 80
7+
arrowParens: avoid

LICENSE

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

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Custom ESLint rules for Angular projects
2+
3+
## What's this?
4+
5+
This is a repository containing custom ESLint rules for Angular projects
6+
7+
## Rules included
8+
9+
`destroy-service-provider`: When using `DestroyService` to automatically unsubscribe from an observable, this service MUST be provided in Component/Directive class providers in order for the Service to work properly. This rule ensures the DestroyService is always provided in the `providers` array of the Component or Directive.
10+
11+
## Usage
12+
13+
Edit your eslint config file as follow
14+
15+
```json
16+
{
17+
"plugins": ["ngx-eslint"],
18+
"rules": {
19+
"ngx-eslint/destroy-service-provider": "error"
20+
}
21+
}
22+
```
23+
24+
## LICENSE
25+
26+
MIT

package.json

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"name": "eslint-plugin-ngx-eslint",
3+
"version": "1.0.0",
4+
"description": "Custom ESLint rules for Angular projects",
5+
"main": "lib/index.js",
6+
"scripts": {
7+
"clean": "rimraf lib",
8+
"prebuild": "rimraf node_modules/@types/eslint/node_modules/@types/estree",
9+
"build": "tsc",
10+
"prettier": "prettier \"*.{js,json,yml,yaml,md}\" \"src/**/*\"",
11+
"format": "yarn prettier --write",
12+
"format:check": "yarn prettier --check",
13+
"test": "jest",
14+
"prepublish": "npm run clean && npm run build"
15+
},
16+
"repository": "https://github.com/phhien203/eslint-plugin-ngx-eslint",
17+
"files": [
18+
"LICENSE",
19+
"README.md",
20+
"package.json",
21+
"lib"
22+
],
23+
"keywords": [
24+
"eslint",
25+
"typescript",
26+
"angular custom eslint",
27+
"ngx-eslint"
28+
],
29+
"author": "Pham Huu Hien",
30+
"license": "MIT",
31+
"devDependencies": {
32+
"@types/eslint": "8.4.2",
33+
"@types/estree": "0.0.51",
34+
"@types/node": "16.11.33",
35+
"@typescript-eslint/parser": "5.21.0",
36+
"eslint": "8.15.0",
37+
"husky": "7.0.4",
38+
"jest": "28.1.0",
39+
"prettier": "2.6.2",
40+
"pretty-quick": "3.1.3",
41+
"rimraf": "3.0.2",
42+
"ts-jest": "28.0.2",
43+
"typescript": "4.6.4"
44+
},
45+
"peerDependencies": {
46+
"eslint": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
47+
},
48+
"jest": {
49+
"globals": {
50+
"ts-jest": {
51+
"diagnostics": false
52+
}
53+
},
54+
"transform": {
55+
"^.+\\.ts$": "ts-jest"
56+
},
57+
"testRegex": "(src/.*\\.test)\\.ts$",
58+
"testPathIgnorePatterns": [
59+
"/node_modules/",
60+
"\\.d\\.ts$",
61+
"lib/.*"
62+
],
63+
"moduleFileExtensions": [
64+
"js",
65+
"ts",
66+
"json"
67+
]
68+
}
69+
}

renovate.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["config:base"]
3+
}

src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import destroyServiceProvider from "./rules/destroy-service-provider";
2+
3+
export = {
4+
rules: {
5+
"destroy-service-provider": destroyServiceProvider,
6+
},
7+
};
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { RuleTester } from "eslint";
2+
3+
import rule from "./destroy-service-provider";
4+
5+
const tester = new RuleTester({
6+
parser: require.resolve("@typescript-eslint/parser"),
7+
parserOptions: { ecmaVersion: 2015 },
8+
});
9+
10+
tester.run("destroy-service-provider", rule, {
11+
valid: [
12+
{
13+
code: `
14+
@Component({
15+
selector: 'my-orgs',
16+
templateUrl: './welcome.component.html',
17+
styleUrls: ['./welcome.component.scss'],
18+
providers: [DestroyService]
19+
})
20+
export class WelcomeComponent implements OnInit {
21+
constructor(
22+
private destroy$: DestroyService,
23+
) {}
24+
}`,
25+
},
26+
{
27+
code: `
28+
@Directive({
29+
selector: 'my-directive',
30+
providers: [DestroyService]
31+
})
32+
export class MyDirective implements OnInit {
33+
constructor(
34+
private destroy$: DestroyService,
35+
) {}
36+
}`,
37+
},
38+
],
39+
invalid: [
40+
{
41+
code: `
42+
@Component({
43+
selector: 'my-orgs',
44+
templateUrl: './welcome.component.html',
45+
styleUrls: ['./welcome.component.scss'],
46+
providers: []
47+
})
48+
export class WelcomeComponent implements OnInit {
49+
constructor(
50+
private destroy$: DestroyService,
51+
) {}
52+
}`,
53+
errors: [
54+
{
55+
message:
56+
"Please provide DestroyService in Component class providers.",
57+
},
58+
],
59+
},
60+
{
61+
code: `
62+
@Directive({
63+
selector: 'my-directive',
64+
})
65+
export class MyDirective implements OnInit {
66+
constructor(
67+
private destroy$: DestroyService,
68+
) {}
69+
}`,
70+
errors: [
71+
{
72+
message:
73+
"Please provide DestroyService in Directive class providers.",
74+
},
75+
],
76+
},
77+
],
78+
});

0 commit comments

Comments
 (0)