Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit

Permalink
[FEAT] [indent] Extend the base rule to support TS nodes (#219)
Browse files Browse the repository at this point in the history
Fixes #201 
Fixes #96 
Fixes eslint/typescript-eslint-parser#577

The [base eslint implementation](https://github.com/eslint/eslint/blob/master/lib/rules/indent.js) purposely ignores nodes it doesn't know about (i.e. our TS nodes).

Because of how the base rule is written, we have to override the implementation entirely.
  • Loading branch information
bradzacher authored Dec 17, 2018
1 parent d98eec9 commit 84808c1
Show file tree
Hide file tree
Showing 6 changed files with 1,570 additions and 13 deletions.
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
"plugin:eslint-plugin/recommended"
],
"rules": {
"new-cap": "off",
"lines-around-comment": "off",

"prettier/prettier": [
"error",
{
"tabWidth": 4
}
],
"lines-around-comment": "off",

"eslint-plugin/prefer-placeholders": "error",
"eslint-plugin/prefer-replace-text": "error",
"eslint-plugin/no-deprecated-report-api": "error",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ This guarantees 100% compatibility between the plugin and the parser.
| [`typescript/explicit-function-return-type`](./docs/rules/explicit-function-return-type.md) | Require explicit return types on functions and class methods | | |
| [`typescript/explicit-member-accessibility`](./docs/rules/explicit-member-accessibility.md) | Require explicit accessibility modifiers on class properties and methods (`member-access` from TSLint) | | |
| [`typescript/generic-type-naming`](./docs/rules/generic-type-naming.md) | Enforces naming of generic type variables | | |
| [`typescript/indent`](./docs/rules/indent.md) | Enforce consistent indentation (`indent` from TSLint) | :heavy_check_mark: | :wrench: |
| [`typescript/interface-name-prefix`](./docs/rules/interface-name-prefix.md) | Require that interface names be prefixed with `I` (`interface-name` from TSLint) | | |
| [`typescript/member-delimiter-style`](./docs/rules/member-delimiter-style.md) | Require a specific member delimiter style for interfaces and type literals | | :wrench: |
| [`typescript/member-naming`](./docs/rules/member-naming.md) | Enforces naming conventions for class members by visibility. | | |
Expand Down
24 changes: 16 additions & 8 deletions docs/rules/camelcase.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ variable that will be imported into the local module scope.

## Options

```cjson
{
// note you must disable the base rule as it can report incorrect errors
"camelcase": "off",
"typescript/camelcase": ["error", { "properties": "always" }]
}
```

This rule has an object option:

* `"properties": "always"` (default) enforces camelcase style for property names
Expand All @@ -33,7 +41,7 @@ This rule has an object option:
Examples of **incorrect** code for this rule with the default `{ "properties": "always" }` option:

```js
/*eslint camelcase: "error"*/
/*eslint typescript/camelcase: "error"*/

import { no_camelcased } from "external-module"

Expand Down Expand Up @@ -73,7 +81,7 @@ var { foo: bar_baz = 1 } = quz;
Examples of **correct** code for this rule with the default `{ "properties": "always" }` option:

```js
/*eslint camelcase: "error"*/
/*eslint typescript/camelcase: "error"*/

import { no_camelcased as camelCased } from "external-module";

Expand Down Expand Up @@ -115,7 +123,7 @@ var { foo: isCamelCased = 1 } = quz;
Examples of **correct** code for this rule with the `{ "properties": "never" }` option:

```js
/*eslint camelcase: ["error", {properties: "never"}]*/
/*eslint typescript/camelcase: ["error", {properties: "never"}]*/

var obj = {
my_pref: 1
Expand All @@ -127,7 +135,7 @@ var obj = {
Examples of **incorrect** code for this rule with the default `{ "ignoreDestructuring": false }` option:

```js
/*eslint camelcase: "error"*/
/*eslint typescript/camelcase: "error"*/

var { category_id } = query;

Expand All @@ -145,7 +153,7 @@ var { category_id: categoryId, ...other_props } = query;
Examples of **incorrect** code for this rule with the `{ "ignoreDestructuring": true }` option:

```js
/*eslint camelcase: ["error", {ignoreDestructuring: true}]*/
/*eslint typescript/camelcase: ["error", {ignoreDestructuring: true}]*/

var { category_id: category_alias } = query;

Expand All @@ -155,7 +163,7 @@ var { category_id, ...other_props } = query;
Examples of **correct** code for this rule with the `{ "ignoreDestructuring": true }` option:

```js
/*eslint camelcase: ["error", {ignoreDestructuring: true}]*/
/*eslint typescript/camelcase: ["error", {ignoreDestructuring: true}]*/

var { category_id } = query;

Expand All @@ -169,15 +177,15 @@ var { category_id: category_id } = query;
Examples of **correct** code for this rule with the `allow` option:

```js
/*eslint camelcase: ["error", {allow: ["UNSAFE_componentWillMount"]}]*/
/*eslint typescript/camelcase: ["error", {allow: ["UNSAFE_componentWillMount"]}]*/

function UNSAFE_componentWillMount() {
// ...
}
```

```js
/*eslint camelcase: ["error", {allow: ["^UNSAFE_"]}]*/
/*eslint typescript/camelcase: ["error", {allow: ["^UNSAFE_"]}]*/

function UNSAFE_componentWillMount() {
// ...
Expand Down
Loading

0 comments on commit 84808c1

Please sign in to comment.