/eslint-plugin-optional-chain

This is an ESLint plugin that provides a custom rule to automatically convert dot operators (.) to optional chain operators (?.) in your code.

Primary LanguageJavaScript

eslint-plugin-optional-chain

This is an ESLint plugin that provides a custom rule to automatically convert dot operators (.) to optional chain operators (?.) in your code.

Installation

You'll first need to install ESLint:

npm i eslint --save-dev

Next, install eslint-plugin-optional-chain:

npm install eslint-plugin-optional-chain --save-dev

Usage

Add optional-chain to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
	"plugins": ["optional-chain"]
}

Then configure the rules you want to use under the rules section.

{
	"rules": {
		"optional-chain/auto-optional-chain": 2
	}
}

TODO

  • ignore assignment expressions

  • Identify the index value(foo['bar'] or array[1])

  • Identify the function call value(foo.bar())

  • ...

Rules

🔧 Automatically fixable by the --fix CLI option.

Name                Description 🔧
auto-optional-chain Automatically convert dot operators (.) to optional chain operators (?.) in your code. 🔧