Skip to content

Commit

Permalink
feat: add typescript config
Browse files Browse the repository at this point in the history
  • Loading branch information
keithamus committed Apr 29, 2020
1 parent a645685 commit fb767cc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 21 deletions.
58 changes: 37 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ Alternatively, you can use the `recommended` configuration which will do this fo
}
```

### TypeScript Users

Aside from the `recommended` config, there is also the `typescript` config which can be used if you're using TypeScript. The TypeScript config only enables some of the rules, avoiding enabling rules for which `typescript` safely transpiles down to a more compatible syntax. To enable the `typescript` config, simply add the following to your eslint config:

```js
// .eslintrc
{
"extends": ["plugin:escompat/typescript"]
}
```

## Targeting Browsers

`eslint-plugin-escompat` uses the `browserslist` configuration in `package.json`
Expand Down Expand Up @@ -55,27 +66,32 @@ See [browserslist/browserslist](https://github.com/browserslist/browserslist) fo

## Rules

- [no-async-generator](./docs/no-async-generator.md)
- [no-async-iteration](./docs/no-async-iteration.md)
- [no-bigint](./docs/no-bigint.md)
- [no-bind-operator](./docs/no-bind-operator.md)
- [no-computed-class-fields](./docs/no-computed-class-fields.md)
- [no-do-expression](./docs/no-do-expression.md)
- [no-dynamic-import](./docs/no-dynamic-import.md)
- [no-edge-destructure-bug](./docs/no-edge-destructure-bug.md)
- [no-exponentiation-operator](./docs/no-exponentiation-operator.md)
- [no-nullish-coalescing](./docs/no-nullish-coalescing.md)
- [no-numeric-separators](./docs/no-numeric-separators.md)
- [no-object-rest-spread](./docs/no-object-rest-spread.md)
- [no-optional-catch](./docs/no-optional-catch.md)
- [no-optional-chaining](./docs/no-optional-chaining.md)
- [no-pipeline-operator](./docs/no-pipeline-operator.md)
- [no-private-class-fields](./docs/no-private-class-fields.md)
- [no-public-instance-class-fields](./docs/no-public-instance-class-fields.md)
- [no-public-static-class-fields](./docs/no-public-static-class-fields.md)
- [no-regexp-lookbehind](./docs/no-regexp-lookbehind.md)
- [no-regexp-named-groups](./docs/no-regexp-named-groups.md)
- [no-regexp-s-flag](./docs/no-regexp-s-flag.md)
- [no-async-generator](./docs/no-async-generator.md) ✔️
- [no-async-iteration](./docs/no-async-iteration.md) ✔️
- [no-bigint](./docs/no-bigint.md) ✔️ 🔹
- [no-bind-operator](./docs/no-bind-operator.md) ✔️ 🔹
- [no-computed-class-fields](./docs/no-computed-class-fields.md) ✔️ 🔹
- [no-do-expression](./docs/no-do-expression.md) ✔️ 🔹
- [no-dynamic-import](./docs/no-dynamic-import.md) ✔️ 🔹
- [no-edge-destructure-bug](./docs/no-edge-destructure-bug.md) ✔️ 🔹
- [no-exponentiation-operator](./docs/no-exponentiation-operator.md) ✔️
- [no-nullish-coalescing](./docs/no-nullish-coalescing.md) ✔️
- [no-numeric-separators](./docs/no-numeric-separators.md) ✔️
- [no-object-rest-spread](./docs/no-object-rest-spread.md) ✔️
- [no-optional-catch](./docs/no-optional-catch.md) ✔️
- [no-optional-chaining](./docs/no-optional-chaining.md) ✔️
- [no-pipeline-operator](./docs/no-pipeline-operator.md) ✔️ 🔹
- [no-private-class-fields](./docs/no-private-class-fields.md) ✔️
- [no-public-instance-class-fields](./docs/no-public-instance-class-fields.md) ✔️
- [no-public-static-class-fields](./docs/no-public-static-class-fields.md) ✔️
- [no-regexp-lookbehind](./docs/no-regexp-lookbehind.md) ✔️ 🔹
- [no-regexp-named-groups](./docs/no-regexp-named-groups.md) ✔️ 🔹
- [no-regexp-s-flag](./docs/no-regexp-s-flag.md) ✔️ 🔹

#### Key:

✔️ = enabled in `plugin:escompat/recommended` config.
🔹 = enabled in `plugin:escompat/typescript` config.

## Inspiration
This project was largely inspired by the great [eslint-plugin-compat][epc] library.
Expand Down
20 changes: 20 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,23 @@ module.exports.configs.recommended = {
parserOptions: { ecmaVersion: 2020 },
rules: Object.keys(module.exports.rules).reduce((o, r) => (o['escompat/' + r] = ['error'], o), {})
}

const allowedTypeScriptRules = new Set([
'no-exponentiation-operator',
'no-async-iteration',
'no-async-generator',
'no-object-rest-spread',
'no-optional-catch',
'no-optional-chaining',
'no-nullish-coalescing',
'no-numeric-separators',
'no-public-static-class-fields',
'no-public-instance-class-fields',
'no-private-class-fields',
])

module.exports.configs.typescript = {
plugins: ['escompat'],
parserOptions: { ecmaVersion: 2020 },
rules: Object.keys(module.exports.rules).filter(rule => !allowedTypeScriptRules.has(rule)).reduce((o, r) => (o['escompat/' + r] = ['error'], o), {})
}

0 comments on commit fb767cc

Please sign in to comment.