Skip to content

Commit

Permalink
feat(eslint-plugin): no-unnecessary-condition (#116)
Browse files Browse the repository at this point in the history
Closes #115 

<!-- We use conventional commits to automate the release process. Please read the [Readme](https://github.com/bamlab/react-native-project-config/blob/main/README.md) for more information. Please follow the commit message format described in the link above. Lerna will automatically generate the changelog for each package based on the commit messages since the last version. -->

- Add the no-unnecessary-condition rule
- Improve the readme for starting up the project
  • Loading branch information
AntoineThibi authored Apr 11, 2024
1 parent 048b3bf commit b09e75d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ There is also an example app under `packages/example-app` whose goal is to demon

- clone the project: `git clone https://github.com/bamlab/react-native-project-config`,
- install the dependencies: `yarn install`,
- build the eslint-plugin: `yarn workspace @bam.tech/eslint-plugin build`

✅ Check : in the example-app in eslint-breaking-examples you should see the eslint errors.

## Modifying the project

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Save without formatting: [⌘ + K] > [S]

// This should trigger one error breaking eslint-plugin-react-native:
// @typescript-eslint/no-unnecessary-condition

export const bar = (arg: string) => {
// arg can never be nullish, so ?. is unnecessary
return arg?.length;
};
8 changes: 8 additions & 0 deletions packages/eslint-plugin/docs/Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ The example-app folder is located at the root of `react-native-project-config`.
The goal of each file of example-app is to simulate the behavior of a rule or a set of rules, so that you can visually check it or by running the `yarn lint` command.
When you add or remove a rule from the recommended config, please modify (or add/remove) the corresponding file in the example-app folder.

## Adding a new rule

In order to add a new rule, you must add it to the packages eslint-plugin, and then build it (it is in typescript) before seeing the changes in the example-app with the command:

```bash
yarn workspace @bam.tech/eslint-plugin build
```

## Real example testing

In order to test that your rule will be properly deployed, use another project, in which you install the eslint-plugin from your local files.
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/lib/configs/recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const recommendedConfig = defineConfig({
"no-return-await": "off", // Disable the base rule as it can report incorrect errors
"@typescript-eslint/return-await": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-unnecessary-condition": "error",
},
},
],
Expand Down

0 comments on commit b09e75d

Please sign in to comment.