Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# https://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{cjs,js,json,jsonld,mjs,yaml,yml}]
indent_style = space
indent_size = 2
11 changes: 0 additions & 11 deletions .eslintrc.js

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/main.yml → .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Lint CI
name: Main CI

on: [push]

Expand All @@ -8,11 +8,11 @@ jobs:
timeout-minutes: 10
strategy:
matrix:
node-version: [14.x]
node-version: [24.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
42 changes: 41 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,44 @@
# eslint-config-digitalbazaar ChangeLog
# @digitalbazaar/eslint-config ChangeLog

### 6.0.0 - 2025-08-xx

### Changed
- **BREAKING**: Rename NPM package from `eslint-config-digitalbazaar` to
`@digitalbazaar/eslint-config`.
- **BREAKING**: Update to `eslint@9`.
- Please see the migration notes below.
- Comments and suggestions welcome for how best to adapt to the rules that
were changed, added, or removed between v8 and v9.
- The way configuration is done changed significantly. Suggestions welcome on
how best to adapt to the new style.
- **BREAKING**: Set `ecmaVersion` to `latest`. Override in project config if a
specific version limitation is required.
- **BREAKING**: Change `'@stylistic/comma-dangle'` to `'never'` from
`'only-multiline'`. Changed to enforce a more uniform style. Override locally
if it causes issues.
- **BREAKING**: Remove `vue` rules for Vue 2. Keep `vue3` as a versioned name.

### Migration
- ESLint v9 is a major breaking change and will require manual updates.
- ESLint has a migration guide:
- https://eslint.org/docs/latest/use/configure/migration-guide
- A few major notes:
- The configuration file changes from multiple `.eslintrc.cjs` or similar to
a single top level `eslint.config.js`.
- Invocation is now `eslint` without options.
- Style rules were deprecated and moved to the `stylistic` project.
- The Digital Bazaar rules are mostly the same as before with updates to
`@stylistic/RULENAME` as needed.
- Note the common `max-len` is now `@stylistic/max-len`.
- Unused rules are now flagged which should help with migration to new rules,
or elimination of unused rules.
- Quasar has not yet updated support for v9. Until that is updated, stay with
v8, or update to v9 and drop Quasar linting and only use Vue linting.
- Major types of rules are grouped together.
- The groups can be composed together as needed.
- There are opinionated "recommended" configs that compose a number of rules
and apply to many common Digital Bazaar repositories.
- See the [README](./README.md) for notes and usage examples.

### 5.2.0 - 2024-05-02

Expand Down
204 changes: 131 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
## eslint-config-digitalbazaar
# Digital Bazaar ESLint Configs _(@digitalbazaar/eslint-config)_

This package provides eslint rules used by Digital Bazaar as a set of extendable shared configs.

There are 6 rule sets:
1. `eslint-config-digitalbazaar`: Base rules for both node and the browser.
2. `eslint-config-digitalbazaar/import`: Rules for es6 imports in the browser and node.
3. `eslint-config-digitalbazaar/jsdoc`: Rules for JSDoc for both node and the browser.
4. `eslint-config-digitalbazaar/module`: Rules for modules for both node and the browser.
5. `eslint-config-digitalbazaar/vue`: Rules for Vue 2 projects and browser only.
6. `eslint-config-digitalbazaar/vue3`: Rules for Vue 3 projects and browser only.
There are various core rule sets:
- `@digitalbazaar/eslint-config`: Base rules for both node and browser code.
- `@digitalbazaar/eslint-config/import`: Rules for es6 imports in the browser and node code.
- `@digitalbazaar/eslint-config/jsdoc`: Rules for JSDoc for both node and browser code.
- `@digitalbazaar/eslint-config/module`: Rules for modules for both node and browser code.
- `@digitalbazaar/eslint-config/vue3`: Rules for Vue 3 code.

For common use cases, there are recommended configs, that load the core rules:
- `@digitalbazaar/eslint-config/browser-recommended`: Recommended rules for projects targeting web browsers.
- `@digitalbazaar/eslint-config/node-recommended`: Recommended rules for projects targeting node.
- `@digitalbazaar/eslint-config/recommended`: Common recommended rules.
- `@digitalbazaar/eslint-config/universal-recommended`: Recommended rules for projects targeting node and web browsers.
- `@digitalbazaar/eslint-config/vue3-recommended`: Recommended rules for projects targeting Vue 3.

## Installation

Requires:
- eslint v9

If you do not have eslint installed:
```
npm i -D eslint
npm i -D eslint-config-digitalbazaar
npm i -D @digitalbazaar/eslint-config
```

To start an eslint config file:
Expand All @@ -25,129 +33,163 @@ npx eslint --init
```
or rename a template from the templates dir
```
cp node_modules/eslint-config-digitalbazaar/templates/node.js ./.eslintrc.cjs
cp node_modules/@digitalbazaar/eslint-config/templates/node-recommended.js ./eslint.config.js
```

## Usage
### Dependencies

**NOTE**: Currently the core and recommended configs may use dependencies that
need to be installed in a project **manually**. This is to avoid requiring
dependencies in this package. A future version may provide alternative packages
with appropriate dependencies.

Dependencies for jsdoc checks:
```
npm i -D eslint-plugin-jsdoc
```

Dependencies for module and node checks:
```
npm i -D eslint-plugin-unicorn
```

All rules can be accessed via the shorthand `digitalbazaar`
or using the full module name `eslint-config-digitalbazaar`.
Dependencies for vue checks:
```
npm i -D eslint-plugin-vue
```

Eslint's documentation on [shareable configs](https://eslint.org/docs/developer-guide/shareable-configs) can be found here.
Dependencies for vue checks when using `legacy-peer-deps=true`:
```
npm i -D vue-eslint-parser
```

Example .eslintrc.cjs root setup:
Most recommended configs use the jsdoc and module checks and dependencies.

## Usage

Config files can use the simple array syntax or the `defineConfig` syntax
(see [shareable configs](https://eslint.org/docs/developer-guide/shareable-configs)).

Example `eslint.config.js` root setup:
```js
module.exports = {
root: true,
// using full module name
extends: ['eslint-config-digitalbazaar']
}
import config from '@digitalbazaar/eslint-config/recommended'

export default [
...config
];
```

Recommended configs (listed above) exist for common use cases. They may be
sufficient on their own when using the opinionated code and file style used by
Digital Bazaar for specific types of pacakges. However, they can also be mixed
and matched and modified as needed. Note that currently required plugin
dependencies must be manually installed when using recommended configs.

### Imports

To use the import rules you need to install [`eslint-plugin-import`](https://github.com/import-js/eslint-plugin-import):
To use the `import` plugin rules you need to install
[`eslint-plugin-import`](https://github.com/import-js/eslint-plugin-import):

```
npm i -D eslint-plugin-import
```

Example .eslintrc.cjs import setup:
Example `eslint.config.js` import setup:
```js
module.exports = {
extends: ['digitalbazaar/import']
}
import config from '@digitalbazaar/eslint-config/recommended'
import importConfig from '@digitalbazaar/eslint-config/import'

export default [
...config,
...importConfig
];
```

### JSDoc

To use the JSDoc rules you will need to install [`eslint-plugin-jsdoc`](https://github.com/gajus/eslint-plugin-jsdoc):
When using the recommended configs, or to use the JSDoc rules standalone, you
need to install
[`eslint-plugin-jsdoc`](https://github.com/gajus/eslint-plugin-jsdoc):

```
npm i -D eslint-plugin-jsdoc
```

Example .eslintrc.cjs JSDoc setup:
Example `eslint.config.js` JSDoc setup:
```js
module.exports = {
// only the JSDoc rules and any rules in parent dirs
extends: ['digitalbazaar/jsdoc']
}
import config from '@digitalbazaar/eslint-config'
import jsdocConfig from '@digitalbazaar/eslint-config/jsdoc'

export default [
...config,
...jsdocConfig
];
```

### Modules

To use ES module code rather than CommonJS, you will need to install [`eslint-plugin-unicorn`](https://github.com/sindresorhus/eslint-plugin-unicorn):
When using the recommended configs, or to use the ES module rules standalone,
you need to install
[`eslint-plugin-unicorn`](https://github.com/sindresorhus/eslint-plugin-unicorn):
```
npm i -D eslint-plugin-unicorn
```

Example .eslintrc.cjs ESM setup:
Example `eslint.config.js` ESM setup:
```js
module.exports = {
// only the module rules and any rules in parent dirs
extends: ['digitalbazaar/module']
}
```

### Vue 2
import config from '@digitalbazaar/eslint-config'
import moduleConfig from '@digitalbazaar/eslint-config/module'

To use the Vue 2 rules you will need to install [`eslint-plugin-vue`](https://eslint.vuejs.org/):
```
npm i -D eslint-plugin-vue
```

Example .eslintrc.cjs Vue setup:
```js
module.exports = {
// only the vue rules and any rules in parent dirs
extends: ['digitalbazaar/vue']
}
export default [
...config,
...moduleConfig
];
```

For command line use you may need to [explicitly enable linting `.vue`
files](https://eslint.vuejs.org/user-guide/#running-eslint-from-the-command-line).

### Vue 3

To use the Vue 3 rules you will need to install [`eslint-plugin-vue`](https://eslint.vuejs.org/):
```
npm i -D eslint-plugin-vue
```

Example .eslintrc.cjs Vue setup:
Example `eslint.config.js` Vue setup:
```js
module.exports = {
// only the vue3 rules and any rules in parent dirs
extends: ['digitalbazaar/vue3']
}
import config from '@digitalbazaar/eslint-config'
import vue3Config from '@digitalbazaar/eslint-config/vue3'

export default [
...config,
...vue3Config
];
```

For command line use you may need to [explicitly enable linting `.vue`
files](https://eslint.vuejs.org/user-guide/#running-eslint-from-the-command-line).

### Composition

The rules do not depend on each other and are composable:
The core rules do not depend on each other and are composable:
```js
module.exports = {
extends: [
'digitalbazaar',
'digitalbazaar/jsdoc',
'digitalbazaar/module'
'digitalbazaar/vue3'
] // 4 rule sets in one file using shorthand.
}
```
import config from '@digitalbazaar/eslint-config'
import jsdocConfig from '@digitalbazaar/eslint-config/jsdoc'
import vue3Config from '@digitalbazaar/eslint-config/vue3'

The rules can also be used together via [cascade configuration](https://eslint.org/docs/user-guide/configuring).
export default [
...config,
...jsdoconfig,
...vue3Config
];
```

## Other Rules

Other rules that are not included above but can be useful:

### `unicorn/prefer-node-protocol`

Use `node:module` style for Node.js modules.
- Use `node:module` style for Node.js modules.
- This is included in the node related recommended configs.

See [`unicorn/prefer-node-protocol`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-node-protocol.md).

Expand All @@ -158,7 +200,23 @@ npm i -D eslint-plugin-unicorn

Rules:
```js
rules: {
'unicorn/prefer-node-protocol': 'error'
import config from '@digitalbazaar/eslint-config'

export default [
...config,
{
rules: {
'unicorn/prefer-node-protocol': 'error'
}
}
];
```

## Commercial Support

Commercial support for this package is available upon request from
Digital Bazaar: support@digitalbazaar.com

## License

[New BSD License (3-clause)](LICENSE) (c) Digital Bazaar, Inc.
Loading