|
1 |
| -# js-eslint |
| 1 | +# js-lint |
| 2 | + |
| 3 | +A batteries-included, TypeScript-aware linting CLI and ESLint flat config bundle for use in Matrix AI JavaScript/TypeScript projects. |
| 4 | + |
| 5 | +- Type-aware linting powered by `@typescript-eslint` using one or more `tsconfig.json` files |
| 6 | +- Built-in support for React, Tailwind, JSX a11y, Prettier, and Matrix AI custom rules |
| 7 | +- Supports Prettier formatting for Markdown and ShellCheck for shell scripts |
| 8 | +- Single command to lint JavaScript/TypeScript, Markdown, and shell scripts |
| 9 | +- Customizable via `matrixai-lint-config.json` and extensible with your own ESLint config |
| 10 | +- CLI options to override config and enable auto-fix |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +```sh |
| 15 | +npm install --save-dev @matrixai/lint |
| 16 | +``` |
| 17 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | +```sh |
| 21 | +matrixai-lint |
| 22 | +``` |
| 23 | + |
| 24 | +To run with autofix: |
| 25 | + |
| 26 | +```sh |
| 27 | +matrixai-lint --fix |
| 28 | +``` |
| 29 | + |
| 30 | +### CLI Options |
| 31 | + |
| 32 | +| Flag | Description | | | |
| 33 | +| ----------------- | ------------------------------------------- | --- | ------------------------------------- | |
| 34 | +| _(no flag)_ | Uses built-in Matrix AI ESLint config | | | |
| 35 | +| `--fix` | Enables auto-fixing via ESLint and Prettier | | | |
| 36 | +| `--user-config` | Uses detected \`eslint.config.[c | m | t]js\` from the project root if found | |
| 37 | +| `--config <path>` | Explicitly use a custom ESLint config file | | | |
| 38 | + |
| 39 | +### Examples |
| 40 | + |
| 41 | +```sh |
| 42 | +matrixai-lint --fix |
| 43 | +matrixai-lint --user-config |
| 44 | +matrixai-lint --config ./eslint.config.js --fix |
| 45 | +``` |
| 46 | + |
| 47 | +## TypeScript Support |
| 48 | + |
| 49 | +The linter is TypeScript-aware and \*\*requires a \*\***`tsconfig.json`** to determine which files to lint and how to parse them. |
| 50 | + |
| 51 | +By default: |
| 52 | + |
| 53 | +- It looks for `tsconfig.json` in the project root |
| 54 | +- Files are selected based on the `include` and `exclude` fields in the tsconfig |
| 55 | + |
| 56 | +### Working with multiple tsconfigs |
| 57 | + |
| 58 | +If your project uses more than one `tsconfig.json` or doesn't have one at the root, you can configure the linter using a `matrixai-lint-config.json` file at the root: |
| 59 | + |
| 60 | +```json |
| 61 | +{ |
| 62 | + "tsconfigPaths": ["./tsconfig.base.json", "./packages/core/tsconfig.json"], |
| 63 | + "forceInclude": ["scripts", "src/overrides"] |
| 64 | +} |
| 65 | +``` |
| 66 | + |
| 67 | +| Field | Type | Description | |
| 68 | +| --------------- | ---------- | ---------------------------------------------------------------------------------------- | |
| 69 | +| `tsconfigPaths` | `string[]` | One or more paths to `tsconfig.json` files | |
| 70 | +| `forceInclude` | `string[]` | Paths to always include, even if excluded by tsconfig (must be included by at least one) | |
| 71 | + |
| 72 | +> ⚠ If a path in `forceInclude` is not included in any of the `tsconfigPaths`, TypeScript will throw a parsing error. |
| 73 | +
|
| 74 | +## ESLint Config Override |
| 75 | + |
| 76 | +You can use your own ESLint config by one of the following methods: |
| 77 | + |
| 78 | +### 1. Inline Custom Config |
| 79 | + |
| 80 | +```sh |
| 81 | +matrixai-lint --config ./eslint.config.js |
| 82 | +``` |
| 83 | + |
| 84 | +### 2. Auto-detect with `--user-config` |
| 85 | + |
| 86 | +```sh |
| 87 | +matrixai-lint --user-config |
| 88 | +``` |
| 89 | + |
| 90 | +This will look for a valid eslint.config file in the project root. |
| 91 | + |
| 92 | +Valid config filenames: |
| 93 | + |
| 94 | +- `eslint.config.js` |
| 95 | +- `eslint.config.cjs` |
| 96 | +- `eslint.config.mjs` |
| 97 | +- `eslint.config.ts` |
| 98 | + |
| 99 | +### 3. Extend the base config |
| 100 | + |
| 101 | +```ts |
| 102 | +// eslint.config.js |
| 103 | +import matrixai from '@matrixai/lint/config'; |
| 104 | + |
| 105 | +export default [ |
| 106 | + ...matrixai, |
| 107 | + { |
| 108 | + rules: { |
| 109 | + '@typescript-eslint/no-explicit-any': 'error', |
| 110 | + 'no-console': 'off', |
| 111 | + }, |
| 112 | + }, |
| 113 | +]; |
| 114 | +``` |
| 115 | + |
| 116 | +## Development |
| 117 | + |
| 118 | +Run `nix develop`, and once you're inside, you can use: |
| 119 | + |
| 120 | +```sh |
| 121 | +# install (or reinstall packages from package.json) |
| 122 | +npm install |
| 123 | +# build the dist |
| 124 | +npm run build |
| 125 | +# run the repl (this allows you to import from ./src) |
| 126 | +npm run tsx |
| 127 | +# run the tests |
| 128 | +npm run test |
| 129 | +# lint the source code |
| 130 | +npm run lint |
| 131 | +# automatically fix the source |
| 132 | +npm run lintfix |
| 133 | +``` |
| 134 | + |
| 135 | +### Docs Generation |
| 136 | + |
| 137 | +```sh |
| 138 | +npm run docs |
| 139 | +``` |
| 140 | + |
| 141 | +See the docs at: https://matrixai.github.io/js-lint/ |
| 142 | + |
| 143 | +### Publishing |
| 144 | + |
| 145 | +Publishing is handled automatically by the staging pipeline. |
| 146 | + |
| 147 | +Prerelease: |
| 148 | + |
| 149 | +```sh |
| 150 | +# npm login |
| 151 | +npm version prepatch --preid alpha # premajor/preminor/prepatch |
| 152 | +git push --follow-tags |
| 153 | +``` |
| 154 | + |
| 155 | +Release: |
| 156 | + |
| 157 | +```sh |
| 158 | +# npm login |
| 159 | +npm version patch # major/minor/patch |
| 160 | +git push --follow-tags |
| 161 | +``` |
| 162 | + |
| 163 | +Manually: |
| 164 | + |
| 165 | +```sh |
| 166 | +# npm login |
| 167 | +npm version patch # major/minor/patch |
| 168 | +npm run build |
| 169 | +npm publish --access public |
| 170 | +git push |
| 171 | +git push --tags |
| 172 | +``` |
0 commit comments