Skip to content

Commit

Permalink
task: update docs for ama rules (#293)
Browse files Browse the repository at this point in the history
* Added ama rules monorepo setup and update details

* Update getting started to give overview and link out to config file

* Update legacy docs
  • Loading branch information
JDMathew authored Jan 8, 2025
1 parent 43253e2 commit add013e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 26 deletions.
52 changes: 49 additions & 3 deletions website/docs/ama/config-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ The library does not perform any accessibility checks on the production build!

:::


## Log Levels

**AMA** guidelines are categorised as:
Expand Down Expand Up @@ -52,9 +51,56 @@ The possible log levels are:
Rules marked with <No /> are considered bad practices and cannot be turned off!
:::

## Customising the Log Levels
## Customizing the Log Levels

A JSON file called `ama.config.json` should have been automatically generated in the project's root folder (If it didn't simply create it). This file is used to customize the log rules, then specify the custom log level for the wanted key. `accessibilityLabelExceptions` can also be specified in this file. Any changes to this file will automatically be picked up by AMA's config and applied to the applications warnings and errors in Dev mode. (You will need to restart your application to see the changes applied)

:::warning
If you are running a monorepo setup this file won't automatically generate and you will have two options customize AMA's config.

<details>
<summary>Options for monorepos (Expand me)</summary>

You have two options to add `userDefinedRules` to AMA's config:

- You can create a symlink to the `ama.rules.json` file in the root of your project _(recommended)_
- You can create a new `ama.rules.json` file in the root of your project and copy this file over the `ama.rules.json` file in `@react-native-ama/internal` package every time you make changes to it.
(This will also need to be done every time you update or delete and reinstall AMA node_modules)

**Option 1:** _(recommended)_

To create a symlink to the `ama.rules.json` file in the root of your project, run the following command:

```bash

# In the root of your App or root of your project create a symlink to the ama.rules.json file
# Adjust the file path as needed depending on where the ama.rules.json file is located in your monorepo relative to the root of your project
ln -s node_modules/@react-native-ama/internal/ama.rules.json ./ama.rules.json
```

Create a JSON file called `ama.config.json` in the project's root folder to customise the log rules, then specify the custom log level for the wanted key.
**Option 2:**

To create a new `ama.rules.json` file in the root of your project, run the following command:

```bash
# In the root of your App or root of your project
# Adjust the file path as needed depending on where the ama.rules.json file is located in your monorepo relative to the root of your project
cp node_modules/@react-native-ama/internal/ama.rules.json ./ama.rules.json
```

Don't forget if you make changes to the `ama.rules.json` file in the root you will need to copy the changes over to the `ama.rules.json` file in the `@react-native-ama/internal` package of your project.

```bash
# In the root of your App or root of your project
# Adjust the file path as needed depending on where the ama.rules.json file is located in your monorepo relative to the root of your project
cp ama.rules.json node_modules/@react-native-ama/internal/ama.rules.json

# Restart your application to see the changes
```

</details>

:::

### Example

Expand Down
17 changes: 1 addition & 16 deletions website/docs/ama/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,7 @@ npm install @react-native-ama/core

### Config File

When you install the `@react-native-ama/core` package, `the ama.rules.json` file should be generated automatically. If this didn't happen you can run the following from the root of your project:

```bash
# Create ama.rules.json with an empty JSON object if it doesn't exist
echo "{}" >> ama.rules.json

# Navigate to the internal directory
cd node_modules/@react-native-ama/internal

# Create symlinks in src and dist directories
ln -s ../../../ama.rules.json src/ama.rules.json
ln -s ../../../ama.rules.json dist/ama.rules.json

# Go back to the root directory
cd -
```
When you install the `@react-native-ama/core` package, `the ama.rules.json` file should be generated automatically in the root of your project. This file can be used to customize AMA Log Levels and Exceptions. If you are running a monorepo setup this file won't automatically generate and you will have two options customize AMA's config.

See more on configuring **AMA** rules and severity [here](./config-file.md).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Install _react-native-ama_ using either `yarn` or `npm`:
npm install react-native-ama
```


### Dependencies

Some component relies on [react-native-reanimated](https://github.com/software-mansion/react-native-reanimated) and/or [react-native-gesture-handler](https://github.com/software-mansion/react-native-gesture-handler),
Expand All @@ -37,8 +36,8 @@ The installation command should have automatically generated the `ama.rules.json
```bash

echo "{}" >> ama.rules.json
cd node_modules/react-native-ama
ln -s ../../ama.rules.json .

ln -s node_modules/react-native-ama/ama.rules.json ama.rules.json
```

### Jest
Expand All @@ -50,10 +49,9 @@ When running a test, if jest fails with the following error:
add those lines to the `.jest.config.js` file:

```js

jest.mock('react-native-ama/dist/commonjs/internal/logger.js', () => {
return {
getContrastCheckerMaxDepth: () => 5,
};
return {
getContrastCheckerMaxDepth: () => 5,
};
});
```

0 comments on commit add013e

Please sign in to comment.