Détail du package

@bonniernews/eslint-config

BonnierNews9.4kMIT2.0.2

ESLint config

eslint, eslintconfig, config, bonniernews

readme

@bonniernews/eslint-config

Test application

Basic ESLint rules used by Bonnier News. The configuration works both with CommonJS and ES6 modules, and the appropriate setup will be used by looking at the projects package.json type property.

For Node versions that support it (version 16 and above), the es2022 environment will also be activated. Otherwise es2021 will be used.

Table of contents

Usage

Install eslint and @bonniernews/eslint-config:

npm install --save-dev eslint @bonniernews/eslint-config

Configuring all rules

Configures all rules, js, ts, tsx, jsx and test rules.

To activate the config, you need to add the following to your eslint.config.js-file:

"use strict";

module.exports = require("@bonniernews/eslint-config");

JavaScript configuration

To activate the config, you need to add the following to your eslint.config.js-file:

"use strict";

module.exports = require("@bonniernews/eslint-config/js");

TypeScript configuration

To activate the config, you need to add the following to your eslint.config.js-file:

"use strict";

module.exports = require("@bonniernews/eslint-config/ts");

React configuration

To activate the config, you need to add the following to your eslint.config.js-file:

"use strict";

module.exports = require("@bonniernews/eslint-config/jsx");

Test configuration

Adds useful plugins and globals for testing with mocha-cakes-2 + chai.

To activate the config, you need to add the following to your eslint.config.js-file (for js):

"use strict";

module.exports = require("@bonniernews/eslint-config/test-js");

or the following (for ts):

"use strict";

module.exports = require("@bonniernews/eslint-config/test-ts");

Typed react configuration

To activate the config, you need to add the following to your eslint.config.js-file:

"use strict";

module.exports = require("@bonniernews/eslint-config/tsx");

Global ignores

To activate this config (in addition to other config(s), using it alone makes no sense), add the following:

"use strict";

const ignores = require("@bonniernews/eslint-config/ignores");

module.exports = [
  ...allYourGoodConfigs,
  ignores
];

Globals

Globals for browsers, etc. that may be needed.

"use strict";

const globals = require("@bonniernews/eslint-config/globals");

module.exports = [
  ...allYourGoodConfigs,
  { files: [ "assets/scripts" ], languageOptions: { globals: globals.browser } }
];

Migrating from 1.X to 2.X

2.X introduces eslint 9 which has a different configuration format. It is recommended to read the eslint migration guide.

A major change from eslint 8 is that only one eslint.config.js file will be used, placing a specific configuration file in a folder will not behave in the same way as in 8 where it would inherit the configuration from files from the root folder, and the new recommendation is to just have one eslint.config.js at the root of the repository.

One major change from eslint 8 is that in order for ignores to be global they need to be added in a single config at the root level. If you just use the @bonniernews/eslint-config you will have it included, but if you construct your own set of rules you need to add it manually to your config file, otherwise eslint will run on files in terraform directories and such.

The different rule sets have changed name and behaviour:

  • @bonniernews/eslint-config will import configs and apply them to the respective targets
  • @bonniernews/eslint-config/js config for js files
  • @bonniernews/eslint-config/ts config for ts files
  • @bonniernews/eslint-config/jsx config for jsx files
  • @bonniernews/eslint-config/tsx config for tsx files
  • @bonniernews/eslint-config/test-js config for test js files using mocha-cakes-2 and chai
  • @bonniernews/eslint-config/test-ts config for test ts files using mocha-cakes-2 and chai
  • @bonniernews/eslint-config/ignores global ignores

Running eslint

Run with:

npx eslint .

Usage in an existing project

  • We advice to remove any husky hooks that uses libraries such as pretty-quick from your package.json
  • Subsequently remove any use of pretty-quick if possible.
  • Remove any previous use of sharable ESLint configs from package.json, i.e.:
    • eslint-config-airbnb
    • eslint-config-google
    • eslint-config-prettier
  • Remove eslint-plugin-prettier from package.json
  • If you get errors similar to the ones below, please update the eslint dependancy.
    • Definition for rule 'no-nonoctal-decimal-escape' was not found
    • Definition for rule 'no-unsafe-optional-chaining' was not found
  • If you still have issues; try updating npm (if you use nvm nvm install-latest-npm) & prettier as-well
  • Remove any 'eslint-disable-line no-unused-expressions' directives added because of chai assertions, they are not needed anymore (eslint-plugin-chai-friendly is used in test).
  • Remove any globals and special rules related to mocha-cakes-2 in your test configuration, they already exist in the @bonniernews/eslint-config/test and @bonniernews/eslint-config/all configs.

Once you complete the steps above run the following:

npx eslint . --fix

Usage with Prettier

If you want to use Prettier, run it before eslint. ESLint should be the final judge, i.e. run:

npx prettier --save .
npx eslint . --fix

This will format the entire code base according to the rules of Prettier and the config.

Enable format on save

Changelog

Can be found here.

Publishing a new version

  1. Prepare the new version
  2. Fill out the CHANGELOG
  3. Ensure that package-lock, et al are up-to-date
  4. Commit
  5. Tag
  6. Publish, when publishing ensure that you have a token in ~/.npmrc with auth for npm.pkg.github.com as we publish both to our own registry and to the npm registry

License

Released under the MIT license.

changelog

Changelog

2.0.2

  • Fixed bad docs.

2.0.1

  • Switched to released 1.0.0 of @bonniernews/eslint-plugin-typescript-rules.

2.0.0

  • Breaking change: switch from eslint 8 to eslint 9 and adapt to the new flat file config format.
  • Breaking change: removed all, test and typescript-react configs. Just importing the index config will enable all configs. For just the specific configs import @bonniernews/eslint-config/js, @bonniernews/eslint-config/ts, @bonniernews/eslint-config/jsx, @bonniernews/eslint-config/test-js, @bonniernews/eslint-config/test-ts, or @bonniernews/eslint-config/tsx. When creating your own set of rules different globals (as an example globals.browser) is available from @bonniernews/eslint-config/globals.

1.2.0

  • Bumped typescript to 5.4.3 and @typescript-eslint to 7.4.0.

1.1.1

  • Include lowercase describe and context blocks in no-only-tests/no-only-tests.

1.1.0

  • Add rule react/jsx-curly-spacing to align jsx curly with js curly.
  • Bumped eslint-plugin-react, eslint-plugin-import and eslint-plugin-n.
  • Moved TypeScript restricted syntax to a seperate package @bonniernews/typescript-rules.
  • Uses @bonniernews/typescript-rules for TypeScript.
  • Added @bonniernews/typescript-rules/disallow-class-extends also for non-typescript.

1.0.2

  • Run tests on all supported node versions
  • Bump @typescript-eslint/eslint-plugin and @typescript-eslint/parser.
  • Use typescript 5.3 for tests

1.0.1

  • Loosen react/jsx-max-props-per-line to allow as many props the developer wants on a single line but enforce 1 prop per line if using multiple lines.

1.0.0

  • Renamed to @bonniernews/eslint-config

0.8.3

  • fixed typescript-react rules to actually check .ts files
  • disabled import/named for typescript

0.8.2

  • bump typescript deps

0.8.1

  • fixed broken release

0.8.0

  • tsx support by using exp/typescript-react
  • removed warning for explicit anys

0.7.0

  • TypeScript rules.
  • Bumped major version of eslint-plugin-n to 16.
  • Bumped major version of eslint-plugin-no-only-tests to 3.
  • Bumped required node version to 16.
  • Added TypeScript as an optional peer dependency.

0.6.2

0.6.1

  • Added "react/jsx-indent-props": [2, 2] as a rule for react to make indenting jsx props look nice.

0.6.0

  • Added support for react using exp/react.

0.5.0

Add deprecated rules for node.

0.4.0

  • Replace eslint-plugin-node with eslint-plugin-n as the former is no longer maintained.

0.3.0

Added missing afterEachFeature & beforeEachFeature globals for mocha-cakes-2.

0.2.0

  • Added support for ES6 module linting, which is activated if "type": "module" in your package.json
  • For Node versions 16 and above, the ES2022 environment will be activated
  • A new configuration exp/all has been added, which adds the test configuration directly in the main .eslintrc.json

0.1.1

Consistent spacing for functions and code blocks.

0.1.0

New rules to format objects: either all properties on the same line OR use multiline.

0.0.9

Updated eslint peer dependency to v8.

0.0.8

eslint-plugin-node is now included in the package and has migrated the following rules:

  • node/handle-callback-err
  • node/no-path-concat
  • node/no-process-exit

Behavior remains unchanged.

0.0.7

function is now exempt from the comma-dangle rule.

0.0.6

Add the comma-dangle rule with always-multiline.

0.0.5

Add the switch-colon-spacing rule.

0.0.4

Remove some ignorePatterns that shouldn't be ignored.

0.0.3

No changes. Fixes bad publish.

0.0.2

Use new-cap in standard configuration.

0.0.1

Initial working version.