Skip to content

Commit 0a3a445

Browse files
authored
docs: use absolute links (#71)
* doc: use absolute links to have correct links in NPM * feat: add markdown lint dependencies * feat: add markdown lint configuration * feat: add markdown lint custom rule * feat: add markdown lint script * doc: correct markdown * feat: add markdown-lint CI workflow * doc : add section about markdown lint
1 parent 72f23d3 commit 0a3a445

File tree

12 files changed

+1277
-769
lines changed

12 files changed

+1277
-769
lines changed

.github/workflows/markdown-lint.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Quality
2+
3+
on: pull_request
4+
5+
jobs:
6+
quality-job:
7+
name: Markdown lint
8+
runs-on: ubuntu-latest
9+
timeout-minutes: 10
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v3
14+
15+
- name: Setup node
16+
id: setup-node
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version-file: packages/eslint-plugin/.nvmrc
20+
21+
- name: Load dependency cache
22+
uses: actions/cache@v3
23+
with:
24+
path: packages/eslint-plugin/node_modules
25+
# add `-patches-${{ hashFiles('patches/**/*') }}` if you use patch-package
26+
key: eslint-${{ runner.os }}-node-${{ steps.setup-node.outputs.node-version }}-modules-${{ hashFiles('yarn.lock') }}
27+
restore-keys: |
28+
eslint-${{ runner.os }}-node-${{ steps.setup-node.outputs.node-version }}-modules-
29+
eslint-${{ runner.os }}-node-${{ steps.setup-node.outputs.node-version }}-
30+
31+
- name: Install dependencies
32+
run: yarn --frozen-lockfile
33+
34+
- name: Markdown lint
35+
run: yarn lint-md

.markdownlint.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"default": true,
3+
"MD013": false
4+
}

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
"editor.defaultFormatter": "esbenp.prettier-vscode",
33
"editor.formatOnSave": true,
44
"editor.codeActionsOnSave": { "source.fixAll": true },
5-
"eslint.workingDirectories": ["example-app", "packages/eslint-plugin"]
5+
"eslint.workingDirectories": ["example-app", "packages/eslint-plugin"],
6+
"markdownlint.customRules": [
7+
"./markdown-lint-custom-rules/no-relative-links.js"
8+
]
69
}

CONTRIBUTING.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
Each package has its own specifications for contribution. Please refer to the `CONTRIBUTING.md` file in the package you want to contribute to.
44

5-
- [eslint-plugin](packages/eslint-plugin/CONTRIBUTING.md)
5+
- [eslint-plugin](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/CONTRIBUTING.md)
66

77
## Conventional commits
88

9-
We use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) to automate the release process. 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. (see [README.md](README.md#publishing-a-new-version-of-a-package))
9+
We use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) to automate the release process. 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. (see [README.md](https://github.com/bamlab/react-native-project-config/blob/main/README.md#publishing-a-new-version-of-a-package))
10+
11+
## markdown lint
12+
13+
We don't use relative links bewteen .md files, NPM handles them differently than github does, and this creates a bug on NPM where the links are broken. On this project you have markdown lint set up. You can download the [markdown lint VSCode extension](https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint), it will lint your .md files as you write them. There is a [custom rule](https://github.com/bamlab/react-native-project-config/blob/main/markdown-lint-custom-rules/no-relative-links.js) that prevents the use of relative links in .md files. You can check it if you need to write a new custom rule. The scipt and the extension use this [configuration file](https://github.com/bamlab/react-native-project-config/blob/main/.vscode/settings.json), and the custom rules that are added in the VS Code [settings](https://github.com/bamlab/react-native-project-config/blob/main/.markdownlint.json)

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ There is also an example app under `packages/example-app` whose goal is to demon
1212

1313
## Using the configurations
1414

15-
- [Using ESLint plugin](./packages/eslint-plugin/README.md)
16-
- [Using Typescript config](./packages/typescript-config/README.md)
15+
- [Using ESLint plugin](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/README.md)
16+
- [Using Typescript config](https://github.com/bamlab/react-native-project-config/blob/main/packages/typescript-config/README.md)
1717

1818
## Installing the project
1919

@@ -32,7 +32,7 @@ Here are some useful commands:
3232

3333
## Publishing a new version of a package
3434

35-
The publication is done automatically by this [Github Workflow](.github/workflows/publish.yml) when a new tag is pushed to the repository.
35+
The publication is done automatically by this [Github Workflow](https://github.com/bamlab/react-native-project-config/blob/main/.github/workflows/publish.yml) when a new tag is pushed to the repository.
3636
All you have to do is the versioning of the packages you want to publish.
3737

3838
> You need to be on the main branch and have the repo write access to publish a new version.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const { URL } = require('url');
2+
module.exports = {
3+
names: ['MDC01', 'no-relative-links'],
4+
description: 'Rule that reports an error for any relative links',
5+
tags: ['links'],
6+
function: (params, onError) => {
7+
params.tokens.filter(token => token.type === 'inline').forEach(token => {
8+
token.children.filter(child => child.type === 'link_open').forEach(child => {
9+
const link = child.attrs.find(attribute => attribute[0] === 'href');
10+
if (link) {
11+
const hrefValue = link[1];
12+
try {
13+
new URL(hrefValue);
14+
} catch (e) {
15+
if (!hrefValue.startsWith('#')) { // Allow anchor links
16+
onError({
17+
lineNumber: child.lineNumber,
18+
detail: `Found a relative link: ${hrefValue}`
19+
});
20+
}
21+
}
22+
}
23+
});
24+
});
25+
}
26+
};

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55
"packages/*",
66
"example-app"
77
],
8+
"scripts": {
9+
"lint-md": "find . -name '*.md' -not -path './node_modules/*' -exec markdownlint --config ./.markdownlint.json --rules ./markdown-lint-custom-rules/no-relative-links.js {} +"
10+
},
811
"devDependencies": {
912
"lerna": "^6.3.0",
13+
"markdownlint": "^0.31.1",
14+
"markdownlint-cli": "^0.37.0",
15+
"markdownlint-rule-helpers": "^0.22.0",
1016
"prettier": "^2.8.1"
1117
}
1218
}

packages/eslint-plugin/.eslint-doc-generatorrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const { prettier: prettierRC } = require("./package.json"); // or wherever your
55
const config = {
66
postprocess: (content, path) =>
77
prettier.format(content, { ...prettierRC, parser: "markdown" }),
8+
urlRuleDoc: path => `
9+
https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/docs/rules/${path}.md`,
810
};
911

1012
module.exports = config;

packages/eslint-plugin/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
99

1010
- disable react-native/no-raw-text ([#60](https://github.com/bamlab/react-native-project-config/issues/60)) ([4a8ace3](https://github.com/bamlab/react-native-project-config/commit/4a8ace36fbf91421461b808c896a048ce5138152))
1111

12-
# [1.0.0](https://github.com/bamlab/react-native-project-config/compare/@bam.tech/[email protected][email protected]/[email protected]) (2023-09-14)
12+
## [1.0.0](https://github.com/bamlab/react-native-project-config/compare/@bam.tech/[email protected][email protected]/[email protected]) (2023-09-14)
1313

1414
### Features
1515

packages/eslint-plugin/CONTRIBUTING.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ It is important to keep it up to date and to add new rules and configurations wh
77

88
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:
99

10-
#### Open an issue to discuss the rule with the community:
10+
### Open an issue to discuss the rule with the community
1111

1212
- 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)
1313
- Fill the template with any relevant information about the rule (why it is needed, how it works, shareable configs to add it to, etc.)
1414
- Submit the issue and share it with the community
1515

16-
#### After the discussion, if the rule is approved, you can create a PR to add the rule to the plugin:
16+
### After the discussion, if the rule is approved, you can create a PR to add the rule to the plugin
1717

1818
- Create a new branch from `main` with the name `feat/plugin-rule-name`
1919
- Go to the corresponding shareable config file (for example `recommended.js`) and add the rule to the `rules` object:
20+
2021
```js
2122
// recommended.js
2223
module.exports = {
@@ -27,9 +28,13 @@ If you feel that a rule could be useful to all react-native new projects, you ca
2728
},
2829
}
2930
```
31+
3032
> 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.
33+
3134
- (Optional) If the plugin the rule is part of is not yet added as a dependency:
35+
3236
- add the plugin in the `plugins` array of the shareable config file:
37+
3338
```js
3439
// recommended.js
3540
module.exports = {
@@ -40,7 +45,9 @@ If you feel that a rule could be useful to all react-native new projects, you ca
4045
],
4146
}
4247
```
48+
4349
- add the plugin to the `peerDependencies` of the `package.json` file:
50+
4451
```json
4552
// package.json
4653
{
@@ -51,9 +58,10 @@ If you feel that a rule could be useful to all react-native new projects, you ca
5158
},
5259
}
5360
```
61+
5462
- 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
5563

56-
#### (OPTIONAL) Feel free to add a breaking example of the rule in the `example-app/eslint-breaking-examples` directory:
64+
#### (OPTIONAL) Feel free to add a breaking example of the rule in the `example-app/eslint-breaking-examples` directory
5765

5866
Here's an example:
5967
@@ -93,6 +101,7 @@ Creating new rules is quite simple:
93101
```
94102
95103
1. Update the README and run the tests:
104+
96105
```bash
97106
yarn update:eslint-docs
98107
yarn lint

packages/eslint-plugin/README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ Then update your `.eslintrc` config file:
3030

3131
This plugin exports multiple configurations that can be used in your `.eslintrc` config file:
3232

33-
| Name | Description |
34-
| ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
35-
| [`@bam.tech/recommended`](./lib/configs/recommended.js) | The recommended config for all projects |
36-
| [`@bam.tech/tests`](./lib/configs/tests.js) | The recommended config for test files. By default this applies to every file: put it in an `overrides` to filter on your test files. |
37-
| [`@bam.tech/a11y`](./lib/configs/a11y.js) | [beta] Eslint config to check for accessibility. Still in beta to not break existing projects, but will be merged into the recommended config in the future. |
33+
| Name | Description |
34+
| -------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
35+
| [`@bam.tech/recommended`](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/lib/configs/recommended.js) | The recommended config for all projects |
36+
| [`@bam.tech/tests`](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/lib/configs/tests.js) | The recommended config for test files. By default this applies to every file: put it in an `overrides` to filter on your test files. |
37+
| [`@bam.tech/a11y`](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/lib/configs/a11y.js) | [beta] Eslint config to check for accessibility. Still in beta to not break existing projects, but will be merged into the recommended config in the future. |
3838

3939
These configs need some peer dependencies. You can list them with:
4040

@@ -59,14 +59,15 @@ This plugin exports some custom rules that you can optionally use in your projec
5959
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
6060
💡 Manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
6161

62-
| Name                                        | Description | 💼 | 🔧 | 💡 |
63-
| :------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------- | :-- | :-- | :-- |
64-
| [accessibility-props-require-accessible](docs/rules/accessibility-props-require-accessible.md) | Requires accessible prop when accessibility props are defined || 🔧 | |
65-
| [do-not-use-role-on-image](docs/rules/do-not-use-role-on-image.md) | Disallow role prop on Image component || 🔧 | |
66-
| [image-requires-accessible-prop](docs/rules/image-requires-accessible-prop.md) | Require accessible prop on image components || 🔧 | 💡 |
67-
| [require-named-effect](docs/rules/require-named-effect.md) | Enforces the use of named functions inside a useEffect | | | |
68-
| [requires-accessibility-label](docs/rules/requires-accessibility-label.md) | Enforces label when component accessible || | 💡 |
69-
| [requires-accessibility-role-when-accessible](docs/rules/requires-accessibility-role-when-accessible.md) | Enforces accessibilityRole or role when component is accessible || | 💡 |
62+
| Name                                        | Description | 💼 | 🔧 | 💡 |
63+
| :------------------------------------------ | :---------- | :-- | :-- | :-- |
64+
65+
| [accessibility-props-require-accessible](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/docs/rules/accessibility-props-require-accessible.md) | Requires accessible prop when accessibility props are defined || 🔧 | |
66+
| [do-not-use-role-on-image](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/docs/rules/do-not-use-role-on-image.md) | Disallow role prop on Image component || 🔧 | |
67+
| [image-requires-accessible-prop](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/docs/rules/image-requires-accessible-prop.md) | Require accessible prop on image components || 🔧 | 💡 |
68+
| [require-named-effect](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/docs/rules/require-named-effect.md) | Enforces the use of named functions inside a useEffect | | | |
69+
| [requires-accessibility-label](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/docs/rules/requires-accessibility-label.md) | Enforces label when component accessible || | 💡 |
70+
| [requires-accessibility-role-when-accessible](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/docs/rules/requires-accessibility-role-when-accessible.md) | Enforces accessibilityRole or role when component is accessible || | 💡 |
7071

7172
<!-- end auto-generated rules list -->
7273

@@ -88,6 +89,6 @@ To use a rule, just declare it in your `.eslintrc`:
8889

8990
You can still customize your ESLint config by adding other configurations, plugins and rules to your `.eslintrc` config file.
9091

91-
## [Contribute](./CONTRIBUTING.md)
92+
## [Contribute](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/CONTRIBUTING.md)
9293

93-
If you find a useful rule that you feel every project at BAM should use, feel free to [contribute](./CONTRIBUTING.md).
94+
If you find a useful rule that you feel every project at BAM should use, feel free to [contribute](https://github.com/bamlab/react-native-project-config/blob/main/packages/eslint-plugin/CONTRIBUTING.md).

0 commit comments

Comments
 (0)