Skip to content

Commit 4d05470

Browse files
committed
feat: Init eslint-plugin-react-native
1 parent 1e0026b commit 4d05470

File tree

13 files changed

+4955
-0
lines changed

13 files changed

+4955
-0
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# For more information about the properties used in
2+
# this file, please see the EditorConfig documentation:
3+
# https://editorconfig.org/
4+
5+
root = true
6+
7+
[*]
8+
charset = utf-8
9+
end_of_line = lf
10+
indent_size = 2
11+
indent_style = space
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
15+
[*.md]
16+
trim_trailing_whitespace = false

.eslintrc.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
3+
module.exports = {
4+
root: true,
5+
env: {
6+
es2022: true,
7+
},
8+
parserOptions: {
9+
ecmaVersion: 'latest',
10+
sourceType: 'module'
11+
},
12+
extends: [
13+
"eslint:recommended",
14+
"plugin:eslint-plugin/recommended",
15+
"plugin:node/recommended",
16+
],
17+
rules: {
18+
"node/no-unpublished-require": ["error", {
19+
"allowModules": ["requireindex"]
20+
}]
21+
},
22+
overrides: [
23+
{
24+
files: ["tests/**/*.js"],
25+
env: { mocha: true },
26+
},
27+
],
28+
};

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules

.vscode/extensions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"esbenp.prettier-vscode",
4+
"dbaeumer.vscode-eslint",
5+
"EditorConfig.EditorConfig"
6+
]
7+
}

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"editor.quickSuggestions": {
3+
"strings": true
4+
},
5+
"editor.formatOnSave": true,
6+
"editor.codeActionsOnSave": {
7+
"source.fixAll.eslint": true
8+
},
9+
"editor.defaultFormatter": "esbenp.prettier-vscode",
10+
"prettier.requireConfig": true
11+
}

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# @sj-distributor/eslint-plugin-react-native
2+
3+
ESLint presets for react native
4+
5+
## Installation
6+
7+
You'll first need to install [ESLint](https://eslint.org/):
8+
9+
```sh
10+
yarn add eslint
11+
12+
or
13+
14+
npm i eslint --save-dev
15+
```
16+
17+
Next, install `@sj-distributor/eslint-plugin-react-native`:
18+
19+
```sh
20+
21+
yarn add @sj-distributor/eslint-plugin-react-native
22+
23+
or
24+
25+
npm install @sj-distributor/eslint-plugin-react-native --save-dev
26+
```
27+
28+
## Usage
29+
30+
Add `eslint-plugin-react-native` to the plugins section of your `.eslintrc` configuration file:
31+
32+
```json
33+
{
34+
"plugins": ["@sj-distributor/eslint-plugin-react-native/recommended"]
35+
}
36+
```

configs/.eslintrc.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"env": {
3+
"es2022": true,
4+
"browser": true,
5+
"react-native/react-native": true
6+
},
7+
"parserOptions": {
8+
"sourceType": "module",
9+
"ecmaVersion": "latest",
10+
"ecmaFeatures": {
11+
"jsx": true
12+
}
13+
},
14+
"extends": [
15+
"eslint:recommended",
16+
"plugin:prettier/recommended",
17+
"plugin:react-hooks/recommended",
18+
"plugin:@typescript-eslint/recommended"
19+
],
20+
"parser": "@typescript-eslint/parser",
21+
"plugins": [
22+
"react",
23+
"react-native",
24+
"simple-import-sort",
25+
"unicorn",
26+
"import"
27+
],
28+
"rules": {
29+
"camelcase": "error",
30+
"spaced-comment": "error",
31+
"import/extensions": "off",
32+
"import/no-unresolved": "off",
33+
"no-duplicate-imports": "error",
34+
"react/react-in-jsx-scope": "off",
35+
"react-hooks/rules-of-hooks": "error",
36+
"simple-import-sort/imports": "error",
37+
"simple-import-sort/exports": "error",
38+
"unicorn/filename-case": [
39+
"error",
40+
{
41+
"cases": {
42+
"kebabCase": true,
43+
"camelCase": false,
44+
"snakeCase": false,
45+
"pascalCase": false
46+
}
47+
}
48+
],
49+
"react-hooks/exhaustive-deps": [
50+
"error",
51+
{
52+
"additionalHooks": "(useMyCustomHook|useMyOtherCustomHook|useRecoilCallback)"
53+
}
54+
]
55+
},
56+
"settings": {
57+
"import/resolver": {
58+
"node": {
59+
"extensions": [".js", ".jsx", ".ts", ".tsx"]
60+
}
61+
},
62+
"react": {
63+
"version": "detect"
64+
}
65+
}
66+
}

docs/rules/demo.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# demo example (demo)
2+
3+
Please describe the origin of the rule here.
4+
5+
## Rule Details
6+
7+
This rule aims to...
8+
9+
Examples of **incorrect** code for this rule:
10+
11+
```js
12+
// fill me in
13+
```
14+
15+
Examples of **correct** code for this rule:
16+
17+
```js
18+
// fill me in
19+
```
20+
21+
### Options
22+
23+
If there are any options, describe them here. Otherwise, delete this section.
24+
25+
## When Not To Use It
26+
27+
Give a short description of when it would be appropriate to turn off this rule.
28+
29+
## Further Reading
30+
31+
If there are other links that describe the issue this rule addresses, please include them here in a bulleted list.

lib/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @fileoverview ESLint presets for react native
3+
*/
4+
"use strict";
5+
6+
//------------------------------------------------------------------------------
7+
// Requirements
8+
//------------------------------------------------------------------------------
9+
10+
const requireIndex = require("requireindex");
11+
const eslintrc = require("../configs/.eslintrc.json");
12+
13+
//------------------------------------------------------------------------------
14+
// Plugin Definition
15+
//------------------------------------------------------------------------------
16+
module.exports = {
17+
// 引入所有的自定义的规则
18+
rules: requireIndex(__dirname + "/rules"),
19+
configs: {
20+
recommended: eslintrc
21+
},
22+
}
23+
24+

lib/rules/demo.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* eslint-disable no-unused-vars */
2+
3+
/**
4+
* @fileoverview demo example
5+
*/
6+
"use strict";
7+
8+
//------------------------------------------------------------------------------
9+
// Rule Definition
10+
//------------------------------------------------------------------------------
11+
12+
/** @type {import('eslint').Rule.RuleModule} */
13+
module.exports = {
14+
meta: {
15+
messages: "demo example",
16+
type: 'suggestion', // `problem`, `suggestion`, or `layout`
17+
docs: {
18+
description: "demo example",
19+
recommended: false,
20+
url: null, // URL to the documentation page for this rule
21+
},
22+
fixable: null, // Or `code` or `whitespace`
23+
schema: [], // Add a schema if the rule has options
24+
},
25+
26+
create(context) {
27+
// variables should be defined here
28+
29+
//----------------------------------------------------------------------
30+
// Helpers
31+
//----------------------------------------------------------------------
32+
33+
// any helper functions should go here or else delete this section
34+
35+
//----------------------------------------------------------------------
36+
// Public
37+
//----------------------------------------------------------------------
38+
39+
return {
40+
// visitor functions for different types of nodes
41+
};
42+
},
43+
};

0 commit comments

Comments
 (0)