|
1 | 1 | # Contribute |
2 | 2 |
|
3 | | -If you find a useful rule that you feel every project at BAM should use, feel free to open a PR. |
| 3 | +This plugin is a way to share the best programming experience via rules and configurations to be used in different projects. |
| 4 | +It is important to keep it up to date and to add new rules and configurations when needed. |
| 5 | + |
| 6 | +## Adding a rule from another plugin |
| 7 | + |
| 8 | +If you feel that a rule could be useful to all react-native new projects, you can add it to the plugin by following these steps: |
| 9 | + |
| 10 | +#### Open an issue to discuss the rule with the community: |
| 11 | + |
| 12 | +- Go to this link : [RFC for a new rule on eslint-plugin ⭐](https://github.com/bamlab/react-native-project-config/issues/new?assignees=&labels=%F0%9F%93%8F+eslint-plugin%2C%E2%AD%90+enhancement&projects=&template=RFC-NEW-RULE.yml&title=%5BRFC%5D%3A+plugin%3Arule-name) |
| 13 | +- Fill the template with any relevant information about the rule (why it is needed, how it works, shareable configs to add it to, etc.) |
| 14 | +- Submit the issue and share it with the community |
| 15 | + |
| 16 | +#### After the discussion, if the rule is approved, you can create a PR to add the rule to the plugin: |
| 17 | + |
| 18 | +- Create a new branch from `main` with the name `feat/plugin-rule-name` |
| 19 | +- Go to the corresponding shareable config file (for example `recommended.js`) and add the rule to the `rules` object: |
| 20 | + ```js |
| 21 | + // recommended.js |
| 22 | + module.exports = { |
| 23 | + ... |
| 24 | + rules: { |
| 25 | + ... |
| 26 | + "plugin-name/rule-name": ["error", { ... }], |
| 27 | + }, |
| 28 | + } |
| 29 | + ``` |
| 30 | + > If you feel a new shareable config should be created for the rule, please refer to the [Creating new shareable configuration](#creating-new-shareable-configuration) section. |
| 31 | +- (Optional) If the plugin the rule is part of is not yet added as a dependency: |
| 32 | + - add the plugin in the `plugins` array of the shareable config file: |
| 33 | + ```js |
| 34 | + // recommended.js |
| 35 | + module.exports = { |
| 36 | + ... |
| 37 | + plugins: [ |
| 38 | + ... |
| 39 | + "plugin-name", |
| 40 | + ], |
| 41 | + } |
| 42 | + ``` |
| 43 | + - add the plugin to the `peerDependencies` of the `package.json` file: |
| 44 | + ```json |
| 45 | + // package.json |
| 46 | + { |
| 47 | + ... |
| 48 | + "peerDependencies": { |
| 49 | + ... |
| 50 | + "plugin-name": "^version", |
| 51 | + }, |
| 52 | + } |
| 53 | + ``` |
| 54 | +- In the description of the PR, add `Closes #<issue number>` to link the PR to the issue and close it automatically when the PR is merged |
| 55 | + |
| 56 | +#### (OPTIONAL) Feel free to add a breaking example of the rule in the `example-app/eslint-breaking-examples` directory: |
| 57 | + |
| 58 | +Here's an example: |
| 59 | +
|
| 60 | +```tsx |
| 61 | +// break-react-eslint-rules.tsx |
| 62 | +
|
| 63 | +// Save without formatting: [⌘ + K] > [S] |
| 64 | +
|
| 65 | +// This should trigger one error breaking eslint-plugin-react: |
| 66 | +// react/jsx-no-undef |
| 67 | +
|
| 68 | +export const MyComponent = () => <ThisIsAViewThatDoesntExist />; |
| 69 | +``` |
4 | 70 |
|
5 | 71 | ## Creating new rules |
6 | 72 |
|
|
0 commit comments