Skip to content

Commit

Permalink
Switch to ES modules (#2)
Browse files Browse the repository at this point in the history
- Switch to ES modules. Keep CJS bundle in `dist`
- Update dependencies
- Apply `template-javascript` project configuration
- Require Node.js version >= 14
- Update ESLint peer dependency to >=8.x
- Update `ci` workflow to reference `master` branch
  • Loading branch information
nikolay-borzov authored May 8, 2022
1 parent 13dc96a commit 958d061
Show file tree
Hide file tree
Showing 24 changed files with 13,712 additions and 5,052 deletions.
1 change: 1 addition & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node 14.16
127 changes: 127 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
module.exports = {
root: true,

parser: '@babel/eslint-parser',
parserOptions: {
sourceType: 'module',
},

ignorePatterns: [
'**/*.*',
'!**/*.js',
'tests/fixtures',
'coverage',
'node_modules',
'dist',
],
env: {
node: true,
},
extends: [
'eslint:recommended',
'plugin:jsdoc/recommended',
'plugin:n/recommended',
'plugin:unicorn/recommended',
'prettier-standard/prettier-file',
],
settings: {
jsdoc: {
mode: 'typescript',
},
},
// Keep rules grouped by plugin and sorted alphabetically
rules: {
'object-shorthand': ['error', 'always'],

'padding-line-between-statements': [
'error',
/* Empty line after import */
{ blankLine: 'always', prev: 'import', next: '*' },
{ blankLine: 'any', prev: 'import', next: 'import' },
/* Empty line before return */
{ blankLine: 'always', prev: '*', next: 'return' },
/* Empty line after const, let */
{ blankLine: 'always', prev: ['const', 'let'], next: '*' },
{ blankLine: 'any', prev: ['const', 'let'], next: ['const', 'let'] },
/* Empty line between case and default inside switch */
{ blankLine: 'always', prev: 'case', next: ['case', 'default'] },
],

/* eslint-plugin-jsdoc */

// Descriptions should be sentence-like not comment-like
'jsdoc/require-description-complete-sentence': 'warn',
'jsdoc/require-hyphen-before-param-description': [
'error',
'never',
{ tags: { property: 'never' } },
],
// Adding JSDoc is preferable but not required
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-param-description': 'off',
'jsdoc/require-property-description': 'off',
'jsdoc/require-returns-description': 'off',
'jsdoc/require-returns': 'off',

'jsdoc/require-param-description': 'off',
'jsdoc/require-returns-description': 'off',

/* eslint-plugin-unicorn */

// I like reduce
'unicorn/no-array-reduce': 'off',

/* eslint-plugin-import */

// Require extension for imports. Required by Node.js with `type: "module"`
'import/extensions': ['error', 'always', { ignorePackages: true }],
// Force using only named exports
'import/no-default-export': 'error',
// Sort imports
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'type',
],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
caseInsensitive: false,
},
},
],

/* eslint-plugin-prettier */

'prettier/prettier': 'warn',

/* eslint-plugin-n (node) */

'n/no-unsupported-features/es-syntax': [
'error',
],
},

overrides: [
// Test files
{
files: 'tests/**/*',
extends: ['plugin:ava/recommended'],
},
// Config CommonJS files
{
files: '*.cjs',
rules: {
/* eslint-plugin-unicorn */

'unicorn/prefer-module': 'off',
},
},
],
}
41 changes: 0 additions & 41 deletions .eslintrc.js

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ name: CI

on:
push:
branches: [ main ]
branches: [ master ]
pull_request:
branches: [ main ]
branches: [ master ]

jobs:
build:

strategy:
matrix:
node-version: [12.x, 14.x]
node-version: [14.x, 16.x]
os: [ windows-latest, ubuntu-latest, macos-latest ]

runs-on: ${{ matrix.os }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 14
- run: npm ci
- run: npm test

Expand All @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 14
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
Expand Down
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit $1
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run test
npx --no-install lint-staged
5 changes: 0 additions & 5 deletions .prettierrc.js

This file was deleted.

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# rollup-plugin-eslint-bundle changelog

## 7.0.0 - 2022-05-08
* Switch to ES modules. But still provide CJS bundle in `dist`
* Update dependencies
* Require Node.js version >= 14
* Update ESLint peer dependency to >=8.x

## 6.0.0 - 2021-01-24
* Rewrite from scratch for latest `rollup` and `ESLint`
* Replace `jest` with `ava`
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Nikolay Borzov
Copyright (c) 2022 Nikolay Borzov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
51 changes: 27 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
[rollup]: https://github.com/rollup/rollup
[eslint-config]: https://eslint.org/docs/developer-guide/nodejs-api#parameters

🍣 A [Rollup] plugin to lint (and fix) bundled code with ESLint.
🍣 A [Rollup] plugin to lint and fix bundled code with ESLint.

## Requirements

This plugin requires an LTS Node version (v12.0.0+), Rollup v2.0.0+ and ESLint 7.0.0+.
This plugin requires an LTS Node version (v14.13.1+), Rollup v2.x and ESLint >=8.x

## Install

Expand All @@ -22,45 +22,43 @@ npm i -D rollup-plugin-eslint-bundle
## Usage

```js
// rollup.config.js
// rollup.config.js ESM
import { rollup } from 'rollup';
import { eslintBundle } from 'rollup-plugin-eslint-bundle';

module.exports = {
input: path.resolve(__dirname, './main.js'),
const root = path.dirname(url.fileURLToPath(import.meta.url))

export default {
input: path.resolve(root, './main.js'),

plugins: [
eslintBundle({
eslintOptions: {
fix: true,
},
throwOnWarning: true,
throwOnError: true,
formatter: 'compact'
}),
],

output: {
file: path.resolve(__dirname, './dist/bundle.js'),
file: path.resolve(root, './dist/bundle.js'),
format: 'es',
plugins: [
eslintBundle({
eslintOptions: {
fix: true,
},
throwOnWarning: true,
throwOnError: true,
formatter: 'compact'
}),
],
},
};

```
```js
// Rollup JavaScript API
const rollup = require('rollup');
const { eslintBundle } = require('rollup-plugin-eslint-bundle');
import { rollup } from 'rollup';
import { eslintBundle } from 'rollup-plugin-eslint-bundle';

// ...

const bundle = await rollup.rollup({
input: 'main.js'
});

await bundle.write({
file: 'dist/bundle.js',
format: 'es',
input: 'main.js',
plugins: [
eslintBundle({
eslintOptions: {
Expand All @@ -73,6 +71,11 @@ await bundle.write({
]
});

await bundle.write({
file: 'dist/bundle.js',
format: 'es',
});

await bundle.close();
```
Expand Down
11 changes: 11 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"comments": false,
"presets": [
[
"@babel/env",
{
"modules": "cjs"
}
]
]
}
23 changes: 23 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { ESLint } from "eslint"
import type { OutputPlugin } from "rollup"

export type Options = {
eslintOptions?: ESLint.Options;
/**
* If `true`, will throw an error if any warnings were found.
*/
throwOnWarning?: boolean;
/**
* If `true`, will throw an error if any errors were found.
*/
throwOnError?: boolean;
/**
* Formatter name or path to be passed to `eslint.loadFormatter()`.
*/
formatter?: string;
}

/**
* Runs ESLint on bundled code.
*/
export function eslintBundle(options?: Options): OutputPlugin
Loading

0 comments on commit 958d061

Please sign in to comment.