Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/eslint-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Then you should add `airbnb` (or `airbnb-base`) to your `extends` section of `.e
| [`@typescript-eslint/camelcase`](./docs/rules/camelcase.md) | Enforce camelCase naming convention | :heavy_check_mark: | |
| [`@typescript-eslint/class-name-casing`](./docs/rules/class-name-casing.md) | Require PascalCased class and interface names (`class-name` from TSLint) | :heavy_check_mark: | |
| [`@typescript-eslint/explicit-function-return-type`](./docs/rules/explicit-function-return-type.md) | Require explicit return types on functions and class methods | :heavy_check_mark: | |
| [`@typescript-eslint/explicit-member-accessibility`](./docs/rules/explicit-member-accessibility.md) | Require explicit accessibility modifiers on class properties and methods (`member-access` from TSLint) | :heavy_check_mark: | |
| [`@typescript-eslint/explicit-member-accessibility`](./docs/rules/explicit-member-accessibility.md) | Require explicit accessibility modifiers on class properties and methods (`member-access` from TSLint) | :heavy_check_mark: | :wrench: |
| [`@typescript-eslint/generic-type-naming`](./docs/rules/generic-type-naming.md) | Enforces naming of generic type variables | | |
| [`@typescript-eslint/indent`](./docs/rules/indent.md) | Enforce consistent indentation (`indent` from TSLint) | :heavy_check_mark: | :wrench: |
| [`@typescript-eslint/interface-name-prefix`](./docs/rules/interface-name-prefix.md) | Require that interface names be prefixed with `I` (`interface-name` from TSLint) | :heavy_check_mark: | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default util.createRule({
category: 'Best Practices',
recommended: 'error',
},
fixable: 'code',
messages: {
missingAccessibility:
'Missing accessibility modifier on {{type}} {{name}}.',
Expand All @@ -38,6 +39,9 @@ export default util.createRule({
type: 'method definition',
name: util.getNameFromPropertyName(methodDefinition.key),
},
fix(fixer) {
return fixer.insertTextBefore(methodDefinition, 'public ');
},
});
}
}
Expand All @@ -60,6 +64,9 @@ export default util.createRule({
type: 'class property',
name: util.getNameFromPropertyName(classProperty.key),
},
fix(fixer) {
return fixer.insertTextBefore(classProperty, 'public ');
},
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ class Test {
getX () {
return 1;
}
}
`,
},
{
filename: 'test.ts',
code: `
class Test {
protected readonly name: string
private readonly x: number
public readonly b: boolean
public getX () {
return this.x
}
}
`,
},
Expand All @@ -62,6 +75,14 @@ class Test {
column: 3,
},
],
output: `
class Test {
public x: number
public getX () {
return this.x
}
}
`,
},
{
filename: 'test.ts',
Expand All @@ -84,6 +105,14 @@ class Test {
column: 3,
},
],
output: `
class Test {
private x: number
public getX () {
return this.x
}
}
`,
},
{
filename: 'test.ts',
Expand Down Expand Up @@ -115,6 +144,44 @@ class Test {
column: 3,
},
],
output: `
class Test {
public x?: number
public getX? () {
return this.x
}
}
`,
},
{
filename: 'test.ts',
code: `
class Test {
readonly x: number
public getX () {
return this.x
}
}
`,
errors: [
{
messageId: 'missingAccessibility',
data: {
type: 'class property',
name: 'x',
},
line: 3,
column: 3,
},
],
output: `
class Test {
public readonly x: number
public getX () {
return this.x
}
}
`,
},
],
});