Skip to content

Commit

Permalink
Upgrade for ESLint 7 (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
briansokol authored Nov 17, 2020
1 parent 5e4fa4e commit 8cd5e45
Show file tree
Hide file tree
Showing 24 changed files with 15,839 additions and 3,116 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
node_modules
base.js
jest.js
node-typescript.js
react-typescript.js
react-native-typescript.js
4 changes: 3 additions & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ config-react-native: react-native-typescript.js

config-node: node-typescript.js

dependencies: yarn.lock
config-jest: jest.js

dependencies: package-lock.json

documentation:
- docs/*.md
Expand Down
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ node_js:
- stable

install:
- yarn install
- npm install -g npm@7
- npm install

script:
- yarn run lint:react
- yarn run lint:node
- yarn run lint:react-native
- npm run lint:react
- npm run lint:node
- npm run lint:react-native
- npm run lint:jest

deploy:
provider: npm
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ISC License (ISC)
Copyright 2019 Brian Sokol
Copyright 2020 Brian Sokol

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

Expand Down
53 changes: 35 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
[![npm Version](https://img.shields.io/npm/v/@bsokol/eslint-config)](https://www.npmjs.com/package/@bsokol/eslint-config)
[![License](https://img.shields.io/npm/l/@bsokol/eslint-config)](https://raw.githubusercontent.com/briansokol/eslint-config/master/LICENSE)
[![Monthly Downloads](https://img.shields.io/npm/dm/@bsokol/eslint-config)](https://www.npmjs.com/package/@bsokol/eslint-config)
[![Known Vulnerabilities](https://snyk.io/test/npm/@bsokol/eslint-config/badge.svg)](https://snyk.io/test/npm/@bsokol/eslint-config)
[![Greenkeeper badge](https://badges.greenkeeper.io/briansokol/eslint-config.svg)](https://greenkeeper.io/)
[![Known Vulnerabilities](https://snyk.io/test/github/briansokol/eslint-config/badge.svg?targetFile=package.json)](https://snyk.io/test/github/briansokol/eslint-config?targetFile=package.json)

I created this library to make it easier for me to stand up a new project. It uses sensible recommended defaults, in addition to some of my personal preferences. You can override the various rules by altering your ESLint config file.

This project uses itself for linting and formatting.

## Documentation

The full list of activated rules can be found [here](docs).

This library adheres to semantic versioning. This means that any change to a rule could be a breaking change for your projects. Therefore, any rule changes will be published as a new major version.
Expand All @@ -18,18 +19,18 @@ This library adheres to semantic versioning. This means that any change to a rul

You must install the following peer dependencies:

- ESLint @ `^6`
- Prettier @ `^1.18`
- TypeScript @ `^3`
- ESLint @ `^7`
- Prettier @ `^2`
- TypeScript @ `>=3`

The exact versions may depend on your existing installation or needs. Here are example commands to install the latest versions:

```bash
npm install eslint@^6 prettier@^1.18 typescript@^3 --save-dev
npm install eslint@^7 prettier@^2 typescript --save-dev
```

```bash
yarn add eslint@^6 prettier@^1.18 typescript@^3 --dev
yarn add eslint@^7 prettier@^2 typescript --dev
```

## Installation
Expand All @@ -51,15 +52,13 @@ This will configure ESLint with the following presets/plugins:
- [React](https://github.com/yannickcr/eslint-plugin-react)
- [React hooks](https://www.npmjs.com/package/eslint-plugin-react-hooks)
- [JSX a11y](https://github.com/evcohen/eslint-plugin-jsx-a11y#readme)
- [Jest](https://github.com/jest-community/eslint-plugin-jest) rules & globals
- [Browserslist compatibility](https://github.com/amilajack/eslint-plugin-compat)
- Browser/CommonJS globals

The list of configured rules can be found [here](docs/react-typescript.md).

### ESLint Configuration

Create a file called `.eslintrc.js` (or the [file format](https://eslint.org/docs/user-guide/configuring) of your choosing) with this config:
Create a file called `.eslintrc.js` (or the [file format](https://eslint.org/docs/user-guide/configuring#using-configuration-files-1) of your choosing) with this config:

```javascript
module.exports = {
Expand All @@ -72,15 +71,14 @@ module.exports = {
This will configure ESLint with the following presets/plugins:

- [TypeScript](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin)
- [Node](https://github.com/mysticatea/eslint-plugin-node)
- [Prettier](https://github.com/prettier/eslint-config-prettier)
- [Jest](https://github.com/jest-community/eslint-plugin-jest) rules & globals
- Node globals

The list of configured rules can be found [here](docs/node-typescript.md).

### ESLint Configuration

Create a file called `.eslintrc.js` (or the [file format](https://eslint.org/docs/user-guide/configuring) of your choosing) with this config:
Create a file called `.eslintrc.js` (or the [file format](https://eslint.org/docs/user-guide/configuring#using-configuration-files-1) of your choosing) with this config:

```javascript
module.exports = {
Expand All @@ -99,23 +97,42 @@ This will configure ESLint with the following presets/plugins:
- [React](https://github.com/yannickcr/eslint-plugin-react)
- [React Native](https://github.com/intellicode/eslint-plugin-react-native) rules and globals
- [React hooks](https://www.npmjs.com/package/eslint-plugin-react-hooks)
- [Jest](https://github.com/jest-community/eslint-plugin-jest) rules & globals

The list of configured rules can be found [here](docs/react-native-typescript.md).

### ESLint Configuration

Create a file called `.eslintrc.js` (or the [file format](https://eslint.org/docs/user-guide/configuring) of your choosing) with this config:
Create a file called `.eslintrc.js` (or the [file format](https://eslint.org/docs/user-guide/configuring#using-configuration-files-1) of your choosing) with this config:

```javascript
module.exports = {
extends: ['@bsokol/eslint-config/react-native-typescript'],
};
```

## Jest

This will configure ESLint with the following presets/plugins:

- [Jest](https://github.com/jest-community/eslint-plugin-jest) rules & globals

The list of configured rules can be found [here](docs/jest.md).

### ESLint Configuration

This preset is an add-on to one of the other preset packages and it assumes your test files will be written in TypeScript.
To use this preset, add it to the `extends` property of your config after the main preset.
For example:

```javascript
module.exports = {
extends: ['@bsokol/eslint-config/react-typescript', '@bsokol/eslint-config/jest'],
};
```

## Prettier Configuration

By default, Prettier will use its own defaults, but you can override them by creating a Prettier config file. The following is an example configuration.
By default, Prettier will use its own defaults, but you can override them by creating a Prettier config file. The following is an **example configuration**.

Create a file called `prettier.config.js` (or the [file format](https://prettier.io/docs/en/configuration.html) of your choosing) with a config similar to this:

Expand All @@ -140,10 +157,10 @@ See the [configuration guide](https://prettier.io/docs/en/configuration.html) fo

## Browserslist Configuration

By default, the language features you use in your code will be linted against the available features in the following browserslist configuration:
By default, the language features you use in your code will be linted against the available features in the following browserslist configuration ("defaults"):

```text
> 0.5%, last 2 versions, Firefox ESR, not dead
```

For more advanced setup and overrides, follow the instructions in the [documentation](https://github.com/amilajack/eslint-plugin-compat#3-configure-target-browsers).
For more advanced setup and overrides, follow the instructions in the [browserslist documentation](https://github.com/amilajack/eslint-plugin-compat#3-configure-target-browsers).
16 changes: 11 additions & 5 deletions base.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
exports.baseConfig = {
exports.default = {
parser: '@typescript-eslint/parser',
extends: [
'eslint:recommended',
'plugin:node/recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/@typescript-eslint',
'plugin:jest/recommended',
'plugin:jest/style',
],
plugins: ['@typescript-eslint/eslint-plugin'],
parserOptions: {
ecmaVersion: 2019,
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: {
impliedStrict: true,
},
},
env: {
node: true,
es6: true,
jest: true,
},
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
Expand Down Expand Up @@ -67,5 +66,12 @@ exports.baseConfig = {
'prefer-object-spread': 'error',
'prefer-rest-params': 'error',
'require-atomic-updates': 'off',
'node/no-unsupported-features/es-syntax': 'off',
'node/no-missing-import': [
'error',
{
tryExtensions: ['.ts', '.js', '.json', '.node'],
},
],
},
};
Loading

0 comments on commit 8cd5e45

Please sign in to comment.