Skip to content

Commit

Permalink
feat!: add conditional TypeScript support to the ESLint config. (#146)
Browse files Browse the repository at this point in the history
* feat!: add conditional TypeScript support to the ESLint config. (#124)

BREAKING CHANGE: Drops support for `eslint` ^6.8.0; `@edx/eslint-config` must now be used with at least `eslint` versions ^7.32.0 or ^8.2.0.

* refactor: updated package-lock

* refactor: updated typescript-eslint parser & plugin

* refactor: updated package-lock

---------

Co-authored-by: Adam Stankiewicz <agstanki@gmail.com>
Co-authored-by: Bilal Qamar <59555732+BilalQamar95@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 5, 2024
1 parent a76103d commit 89d0227
Show file tree
Hide file tree
Showing 4 changed files with 1,142 additions and 397 deletions.
22 changes: 22 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
const path = require('path');
const fs = require('fs');

/**
* TypeScript configuration for ESLint:
*
* Determine whether a `tsconfig.json` file exists in the root folder of the consuming
* project. If it exists, ensure ESLint is configured for TypeScript appropriately.
*/
const typeScriptParserOptions = {};
const typeScriptExtensions = [];
const tsConfigPath = path.resolve(process.cwd(), 'tsconfig.json');
if (fs.existsSync(tsConfigPath)) {
typeScriptParserOptions.project = tsConfigPath;
typeScriptExtensions.push('airbnb-typescript');
}
/* End TypeScript configuration for ESLint */

module.exports = {
env: {
es6: true,
Expand All @@ -11,7 +29,11 @@ module.exports = {
// as peer dependencies.
'airbnb',
'airbnb/hooks',
...typeScriptExtensions,
],
parserOptions: {
...typeScriptParserOptions,
},
// If you add rule overrides here, add code to test.js that proves you formatted it right.
rules: {
'class-methods-use-this': 'off',
Expand Down
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
[![Build Status](https://api.travis-ci.org/edx/eslint-config.svg?branch=master)](https://travis-ci.org/edx/eslint-config)
[![Build Status](https://github.com/openedx/eslint-config/actions/workflows/release.yml/badge.svg)](https://github.com/openedx/eslint-config/actions/workflows/release.yml/)
[![NPM Version](https://img.shields.io/npm/v/@edx/eslint-config.svg)](https://www.npmjs.com/package/@edx/eslint-config)
[![npm_downloads](https://img.shields.io/npm/dt/@edx/eslint-config.svg)](https://www.npmjs.com/package/@edx/eslint-config)
[![license](https://img.shields.io/npm/l/@edx/eslint-config.svg)](https://github.com/openedx/eslint-config/blob/master/LICENSE)
[![semantic release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

# eslint-config
# @edx/eslint-config

## Installation

If you're using @edx/frontend-build, then you'll get this package for free. Otherwise, you can install it via:

```
```shell
npx install-peerdeps --dev @edx/eslint-config
```

This will install the package and all of its peer dependencies.

Then, once it's installed, create an `.eslintrc.js` file in the top-level directory of your project with the following contents:

```
```js
module.exports = {
extends: "@edx/eslint-config",
}
```

### Using TypeScript

If `@edx/eslint-config` detects a `tsconfig.json` file in the root folder of your project, it will optionally configure ESLint to add support for TypeScript. If a `tsconfig.json` file exists, the ESLint config will:
* Extend `airbnb-typescript` ([source](https://www.npmjs.com/package/eslint-config-airbnb-typescript)).
* Configure `parserOptions.project` to point to the `tsconfig.json` file in the root folder of your project.

`airbnb-typescript` may only be extended if a `tsconfig.json` file exists in your project.

If your `tsconfig.json` file is defined somewhere other than the root folder of your project, you may override the default ESLint configuration by extending `airbnb-typescript` and including the path to your `tsconfig.json` file in the `parserOptions.project` ESLint configuration.
Loading

0 comments on commit 89d0227

Please sign in to comment.