Skip to content

Commit

Permalink
chore(eslint-plugin): rename rule to class-literal-property-style
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Mar 23, 2020
1 parent 92c6b34 commit 9647f56
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/eslint-plugin/README.md
Expand Up @@ -99,7 +99,7 @@ Pro Tip: For larger codebases you may want to consider splitting our linting int
| [`@typescript-eslint/await-thenable`](./docs/rules/await-thenable.md) | Disallows awaiting a value that is not a Thenable | :heavy_check_mark: | | :thought_balloon: |
| [`@typescript-eslint/ban-ts-comment`](./docs/rules/ban-ts-comment.md) | Bans `// @ts-<directive>` comments from being used | | | |
| [`@typescript-eslint/ban-types`](./docs/rules/ban-types.md) | Bans specific types from being used | :heavy_check_mark: | :wrench: | |
| [`@typescript-eslint/class-literals-style`](./docs/rules/class-literals-style.md) | Ensures that literals on classes are exposed in a consistent style | | :wrench: | |
| [`@typescript-eslint/class-literal-property-style`](./docs/rules/class-literal-property-style.md) | Ensures that literals on classes are exposed in a consistent style | | :wrench: | |
| [`@typescript-eslint/consistent-type-assertions`](./docs/rules/consistent-type-assertions.md) | Enforces consistent usage of type assertions | :heavy_check_mark: | | |
| [`@typescript-eslint/consistent-type-definitions`](./docs/rules/consistent-type-definitions.md) | Consistent with type definition either `interface` or `type` | | :wrench: | |
| [`@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: | | |
Expand Down
@@ -1,4 +1,4 @@
# Ensures that literals on classes are exposed in a consistent style (`class-literals-style`)
# Ensures that literals on classes are exposed in a consistent style (`class-literal-property-style`)

When writing TypeScript applications, it's typically safe to store literal values on classes using fields with the `readonly` modifier to prevent them from being reassigned.
When writing TypeScript libraries that could be used by Javascript users however, it's typically safer to expose these literals using `getter`s, since the `readonly` modifier is enforced at compile type.
Expand All @@ -18,7 +18,7 @@ This style checks for any getter methods that return literal values, and require
Examples of **correct** code with the `fields` style:

```ts
/* eslint @typescript-eslint/class-literals-style: ["error", "fields"] */
/* eslint @typescript-eslint/class-literal-property-style: ["error", "fields"] */

class Mx {
public readonly myField1 = 1;
Expand All @@ -37,7 +37,7 @@ class Mx {
Examples of **incorrect** code with the `fields` style:

```ts
/* eslint @typescript-eslint/class-literals-style: ["error", "fields"] */
/* eslint @typescript-eslint/class-literal-property-style: ["error", "fields"] */

class Mx {
public static get myField1() {
Expand All @@ -59,7 +59,7 @@ as it will identify fields that can be `readonly`, and thus should be made into
Examples of **correct** code with the `getters` style:

```ts
/* eslint @typescript-eslint/class-literals-style: ["error", "getters"] */
/* eslint @typescript-eslint/class-literal-property-style: ["error", "getters"] */

class Mx {
// no readonly modifier
Expand All @@ -81,7 +81,7 @@ class Mx {
Examples of **incorrect** code with the `getters` style:

```ts
/* eslint @typescript-eslint/class-literals-style: ["error", "getters"] */
/* eslint @typescript-eslint/class-literal-property-style: ["error", "getters"] */

class Mx {
readonly myField1 = 1;
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/configs/all.json
Expand Up @@ -8,7 +8,7 @@
"@typescript-eslint/ban-types": "error",
"brace-style": "off",
"@typescript-eslint/brace-style": "error",
"@typescript-eslint/class-literals-style": "error",
"@typescript-eslint/class-literal-property-style": "error",
"comma-spacing": "off",
"@typescript-eslint/comma-spacing": "error",
"@typescript-eslint/consistent-type-assertions": "error",
Expand Down
Expand Up @@ -41,7 +41,7 @@ const isSupportedLiteral = (
};

export default util.createRule<Options, MessageIds>({
name: 'class-literals-style',
name: 'class-literal-property-style',
meta: {
type: 'problem',
docs: {
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/index.ts
Expand Up @@ -7,7 +7,7 @@ import banTypes from './ban-types';
import braceStyle from './brace-style';
import camelcase from './camelcase';
import classNameCasing from './class-name-casing';
import classLiteralsStyle from './class-literals-style';
import classLiteralPropertyStyle from './class-literal-property-style';
import commaSpacing from './comma-spacing';
import consistentTypeAssertions from './consistent-type-assertions';
import consistentTypeDefinitions from './consistent-type-definitions';
Expand Down Expand Up @@ -103,7 +103,7 @@ export default {
'brace-style': braceStyle,
camelcase: camelcase,
'class-name-casing': classNameCasing,
'class-literals-style': classLiteralsStyle,
'class-literal-property-style': classLiteralPropertyStyle,
'comma-spacing': commaSpacing,
'consistent-type-assertions': consistentTypeAssertions,
'consistent-type-definitions': consistentTypeDefinitions,
Expand Down
@@ -1,11 +1,11 @@
import rule from '../../src/rules/class-literals-style';
import rule from '../../src/rules/class-literal-property-style';
import { RuleTester } from '../RuleTester';

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
});

ruleTester.run('class-literals-style', rule, {
ruleTester.run('class-literal-property-style', rule, {
valid: [
'class Mx { declare readonly p1 = 1; }',
'class Mx { readonly p1 = "hello world"; }',
Expand Down

0 comments on commit 9647f56

Please sign in to comment.