Skip to content

Commit

Permalink
docs: setup docs (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalexiei committed Sep 18, 2024
1 parent 0a917a6 commit d1d18d9
Show file tree
Hide file tree
Showing 9 changed files with 619 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ jobs:
fail-fast: true
matrix:
script: ["lint", "format"]
include:
- needsBuild: true
script: "lint"

steps:
- name: Checkout
Expand All @@ -73,5 +76,9 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Build
if: ${{ matrix.needsBuild }}
run: pnpm build

- name: Run ${{ matrix.script }}
run: pnpm run ${{ matrix.script }}
5 changes: 4 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
pnpm-lock.yaml
pnpm-lock.yaml
# handled by eslint-doc-generator
README.md
*/*.md
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Contributing

## Setup

TODO

## Documentation changes

```shell
pnpm run update:eslint-docs
```

> [!WARNING]
> Right now since there is only one rule documentation process
> do not fall under any linting operation
73 changes: 72 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,75 @@
>
> Check [#1](https://github.com/marcalexiei/eslint-plugin-react-import/issues/1)
ESLint plugin to ensure consistent react imports and relative usage
ESLint plugin to ensure consistent react imports

> [!WARNING]
> This plugin supports `eslint >= 9` and only exposes flat configs
## Rules

<!-- begin auto-generated rules list -->

💼 Configurations enabled in.\
✅ Set in the `recommended` configuration.\
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).

| Name   | Description | 💼 | 🔧 |
| :----------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------- | :- | :- |
| [syntax](docs/rules/syntax.md) | Enforces React import style across your code. Can be customized to use default or namespace import. By default converts exports using namespace import || 🔧 |

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

## Installation

```shell
npm i --save-dev eslint eslint-plugin-react-import
```

```shell
yarn add --dev eslint eslint-plugin-react-import
```

```shell
pnpm add --save-dev eslint eslint-plugin-react-import
```

## Configuration

> [!TIP]
> For a working example check `tests/fixtures` folders
### Javascript

```js
// eslint.config.js
import eslintPluginReactImport from "eslint-plugin-react-import";
export default [
// other configs
// ...
eslintPluginReactImport.configs.recommended,
];
```

### Typescript

> [!NOTE]
> In order to replace all type occurrences typescript parser should be used
```js
// eslint.config.js
import eslintPluginReactImport from "eslint-plugin-react-import";
import typescriptEslintParser from "@typescript-eslint/parser";

export default [
// other configs
// ...
{
...eslintPluginReactImport.configs.recommended,
languageOptions: {
...eslintPluginReactImport.configs.recommended.languageOptions,
parser: typescriptEslintParser,
},
},
];
```
55 changes: 55 additions & 0 deletions docs/rules/syntax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Enforces React import style across your code. Can be customized to use default or namespace import. (`react-import/syntax`)

💼 This rule is enabled in the ✅ `recommended` config.

🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).

<!-- end auto-generated rule header -->

Examples of **incorrect** code for this rule:

```js
import React, { useState } from "react";
```

Examples of **correct** code for this rule:

```js
import * as React from "react";
```

## Options

```text
"react-import/syntax": [<enabled>, <'namespace' | 'default'>]
```

This rule has one string options that allows to choose the preferred syntax for React imports:

### `namespace` (default)

```js
import React, { useState } from "react";
```

Examples of **correct** code for this rule:

```js
import * as React from "react";
```

### `default`

```js
import * as React from "react";
```

Examples of **correct** code for this rule:

```js
import React from "react";
```

## When Not To Use It

If you do not care about React import consistencies
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,27 @@
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"homepage": "https://github.com/marcalexiei/eslint-plugin-react-import",
"keywords": [],
"files": [
"dist"
],
"author": "Marco Pasqualetti @marcalexiei",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/marcalexiei/eslint-plugin-react-import.git"
},
"scripts": {
"build": "tsc -p tsconfig.build.json",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"lint": "pnpm run lint:js && eslint-doc-generator",
"lint:js": "eslint .",
"lint:js:fix": "eslint . --fix",
"lint:docs": "eslint-doc-generator --check",
"format": "prettier . --check",
"format:fix": "prettier . --write",
"test": "vitest"
"test": "vitest",
"update:eslint-docs": "pnpm run build && eslint-doc-generator"
},
"packageManager": "[email protected]+sha512.73a29afa36a0d092ece5271de5177ecbf8318d454ecd701343131b8ebc0c1a91c487da46ab77c8e596d6acf1461e3594ced4becedf8921b074fbd8653ed7051c",
"devDependencies": {
Expand All @@ -34,6 +42,7 @@
"@types/node": "20.16.5",
"@typescript-eslint/parser": "8.6.0",
"eslint": "9.10.0",
"eslint-doc-generator": "1.7.1",
"eslint-plugin-eslint-plugin": "6.2.0",
"eslint-plugin-n": "17.10.2",
"prettier": "3.3.3",
Expand Down
Loading

0 comments on commit d1d18d9

Please sign in to comment.