Skip to content

Commit

Permalink
refactor!: add support for nuxt 3/nuxt bridge (#70)
Browse files Browse the repository at this point in the history
* refactor: add support for nuxt 3/nuxt bridge

* chore: update module

* chore: update module

* chore: update module

* test: add simple test

* chore: use `hookOnce`

* docs: spli pnpm, yarn and npm
  • Loading branch information
ricardogobbosouza committed Mar 8, 2023
1 parent cd820c0 commit 1bfc0ce
Show file tree
Hide file tree
Showing 22 changed files with 8,064 additions and 11,873 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# editorconfig.org
root = true

[*]
Expand Down
31 changes: 13 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,28 @@ jobs:

strategy:
matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest]
node: [12]
node: [16]

steps:
- uses: actions/checkout@v3
- run: corepack enable
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: "pnpm"

- name: checkout
uses: actions/checkout@v3
- name: 📦 Install dependencies
run: pnpm install --frozen-lockfile

- name: cache node_modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ matrix.os }}-node-v${{ matrix.node }}-deps-${{ hashFiles(format('{0}{1}', github.workspace, '/yarn.lock')) }}

- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: yarn
- name: 🚧 Set up project
run: pnpm dev:prepare

- name: Lint
run: yarn lint
- name: 🛠 Build project
run: pnpm build

- name: Test
run: yarn test
- name: 🧪 Test project
run: pnpm test

- name: Coverage
- name: 🟩 Coverage
uses: codecov/codecov-action@v3
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ coverage
dist
sw.*
.env
.output
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shamefully-hoist=true
156 changes: 72 additions & 84 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,59 @@
[![Codecov][codecov-src]][codecov-href]
[![License][license-src]][license-href]

> ESLint module for Nuxt.js
> ESLint module for Nuxt
[📖 **Release Notes**](./CHANGELOG.md)

## Requirements

You need to ensure that you have `eslint >= 7` installed:

With `pnpm`

```bash
pnpm add -D eslint
```

Or, with `yarn`

```bash
yarn add --dev eslint # or npm install --save-dev eslint
yarn add -D eslint
```

Or, with `npm`

```bash
npm install -D eslint
```

## Setup

1. Add `@nuxtjs/eslint-module` dependency to your project

With `pnpm`

```bash
yarn add --dev @nuxtjs/eslint-module # or npm install --save-dev @nuxtjs/eslint-module
pnpm add @nuxtjs/eslint-module
```

2. Add `@nuxtjs/eslint-module` to the `buildModules` section of `nuxt.config.js`
Or, with `yarn`

```bash
yarn add @nuxtjs/eslint-module
```

Or, with `npm`

```bash
npm install @nuxtjs/eslint-module
```

2. Add `@nuxtjs/eslint-module` to the `modules` section of `nuxt.config.js`

```js
export default {
buildModules: [
modules: [
// Simple usage
'@nuxtjs/eslint-module',

Expand All @@ -40,13 +68,11 @@ export default {
}
```

:warning: If you are using Nuxt **< v2.9** you have to install the module as a `dependency` (No `--dev` or `--save-dev` flags) and use `modules` section in `nuxt.config.js` instead of `buildModules`.

### Using top level options

```js
export default {
buildModules: [
modules: [
'@nuxtjs/eslint-module'
],
eslint: {
Expand All @@ -57,11 +83,11 @@ export default {

## Options

You can pass [eslint options](https://eslint.org/docs/developer-guide/nodejs-api#-new-eslintoptions).
You can pass [eslint options](https://eslint.org/docs/latest/integrate/nodejs-api#-new-eslintoptions).

Note that the config option you provide will be passed to the `ESLint` class.
This is a different set of options than what you'd specify in `package.json` or `.eslintrc`.
See the [eslint docs](https://eslint.org/docs/developer-guide/nodejs-api#-new-eslintoptions) for more details.
See the [eslint docs](https://eslint.org/docs/latest/integrate/nodejs-api#-new-eslintoptions) for more details.

### `cache`

Expand All @@ -70,129 +96,91 @@ See the [eslint docs](https://eslint.org/docs/developer-guide/nodejs-api#-new-es

**Note**: The cache is enabled by default to decrease execution time.

### `context`

- Type: `String`
- Default: `srcDir`

A string indicating the root of your files.

### `eslintPath`

- Type: `String`
- Default: `eslint`

Path to `eslint` instance that will be used for linting.

### `exclude`

- Type: `String|Array[String]`
- Default: `'node_modules'`
- Type: `Array[String]`
- Default: `['**/node_modules/**']]`

Specify the files and/or directories to exclude. Must be relative to `options.context`.
Specify the files and/or directories to exclude.

### `extensions`

- Type: `String|Array[String]`
- Default: `['js', 'ts', 'vue']`
- Default: `['js', 'jsx', 'ts', 'tsx', 'vue']`

Specify extensions that should be checked.

### `files`
### `eslintPath`

- Type: `String|Array[String]`
- Default: `null`
- Type: `String`
- Default: `eslint`

Specify directories, files, or globs. Must be relative to `options.context`.
Directories are traversed recursively looking for files matching `options.extensions`.
File and glob patterns ignore `options.extensions`.
Path to `eslint` instance that will be used for linting.

### `fix`
#### `emitError`

- Type: `Boolean`
- Default: `false`

Will enable [ESLint autofix feature](https://eslint.org/docs/developer-guide/nodejs-api#cliengineoutputfixes).

**Be careful: this option will change source files.**

### `formatter`
- Default: `true`

- Type: `String|Function`
- Default: `'stylish'`
The errors found will be printed.

Accepts a function that will have one argument: an array of eslint messages (object). The function must return the output as a string. You can use official [eslint formatters](https://eslint.org/docs/user-guide/formatters/).

### `lintDirtyModulesOnly`
#### `emitWarning`

- Type: `Boolean`
- Default: `true`

Lint only changed files, skip lint on start.

### `threads`

- Type: `Boolean | Number`
- Default: `false`
The warnings found will be printed.

Will run lint tasks across a thread pool. The pool size is automatic unless you specify a number.

### Errors and Warning

**By default the plugin will auto adjust error reporting depending on eslint errors/warnings counts.**
You can still force this behavior by using `emitError` **or** `emitWarning` options:

#### `emitError`
#### `failOnWarning`

- Type: `Boolean`
- Default: `false`

Will always return errors, if set to `true`.
Will cause the module build to fail if there are any warnings, based on `emitWarning`.

#### `emitWarning`
#### `failOnError`

- Type: `Boolean`
- Default: `false`

Will always return warnings, if set to `true`.
Will cause the module build to fail if there are any errors, based on `emitError`.

#### `failOnError`
### `fix`

- Type: `Boolean`
- Default: `false`

Will cause the module build to fail if there are any errors, if set to `true`.
Auto fix source code.

#### `failOnWarning`
**Be careful: this option will change source files.**

- Type: `Boolean`
- Default: `false`
### `formatter`

Will cause the module build to fail if there are any warnings, if set to `true`.
- Type: `String|Function`
- Default: `'stylish'`

#### `quiet`
Accepts a function that will have one argument: an array of eslint messages (object). The function must return the output as a string. You can use official [eslint formatters](https://eslint.org/docs/user-guide/formatters/).

- Type: `Boolean`
- Default: `false`
### `lintOnStart`

Will process and report errors only and ignore warnings, if set to `true`.
- Type: `Boolean`
- Default: `true`

#### `outputReport`
Check all matching files on project startup, too slow, turn on discreetly.

- Type: `Boolean|Object`
- Default: `false`
## Contributing

Write the output of the errors to a file, for example a checkstyle xml file for use for reporting on Jenkins CI.
You can contribute to this module online with CodeSandBox:

The `filePath` is an absolute path or relative to the webpack config: `output.path`.
You can pass in a different `formatter` for the output file,
if none is passed in the default/configured formatter will be used.
[![Edit @nuxtjs/robots](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/nuxt-community/eslint-module/?fontsize=14&hidenavigation=1&theme=dark)

## Development
Or locally:

1. Clone this repository
2. Install dependencies using `yarn install` or `npm install`
3. Start development server using `npm run dev`
2. Install dependencies using `pnpm install`
3. Prepare development server using `pnpm dev:prepare`
4. Build module using `pnpm build`
5. Launch playground using `pnpm dev`

## License

Expand Down
4 changes: 0 additions & 4 deletions jest.config.js

This file was deleted.

48 changes: 28 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,55 @@
{
"name": "@nuxtjs/eslint-module",
"version": "3.1.0",
"description": "ESLint module for Nuxt.js",
"description": "ESLint module for Nuxt",
"repository": "nuxt-community/eslint-module",
"license": "MIT",
"contributors": [
"Ricardo Gobbo de Souza <ricardogobbosouza@yahoo.com.br>"
],
"main": "./dist/module.js",
"types": "./dist/module.d.ts",
"type": "module",
"sideEffects": false,
"exports": {
".": {
"require": "./dist/module.cjs",
"import": "./dist/module.mjs"
}
},
"main": "./dist/module.cjs",
"types": "./dist/types.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "siroc build",
"dev": "nuxt dev test/fixture/basic",
"lint": "eslint --ext .js,.ts,.vue .",
"prepublishOnly": "yarn build",
"release": "yarn test && yarn build && standard-version && git push --follow-tags && npm publish",
"test": "yarn lint && yarn jest"
"build": "nuxt-module-build",
"dev": "nuxi dev playground",
"dev:build": "nuxi build playground",
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
"lint": "eslint --ext .js,.ts,.vue",
"prepack": "pnpm build",
"release": "pnpm test && pnpm build && changelogen --release && git push --follow-tags && pnpm publish",
"test": "pnpm lint && vitest run --coverage"
},
"dependencies": {
"consola": "^2.15.3",
"defu": "^6.0.0",
"eslint-webpack-plugin": "^2.6.0"
"@nuxt/kit": "^3.2.3",
"eslint-webpack-plugin": "^4.0.0",
"vite-plugin-eslint": "^1.8.1"
},
"devDependencies": {
"@babel/preset-typescript": "latest",
"@nuxt/module-builder": "latest",
"@nuxt/test-utils": "latest",
"@nuxt/types": "latest",
"@nuxtjs/eslint-config-typescript": "latest",
"@types/jest": "latest",
"@types/node": "latest",
"@vitest/coverage-c8": "latest",
"changelogen": "latest",
"eslint": "latest",
"jest": "latest",
"nuxt": "latest",
"siroc": "latest",
"standard-version": "latest"
"vitest": "latest"
},
"peerDependencies": {
"eslint": ">=7"
},
"publishConfig": {
"access": "public"
}
},
"packageManager": "pnpm@7.28.0"
}
Loading

0 comments on commit 1bfc0ce

Please sign in to comment.