From a985353b68d4ff6bd686c83eb50593fa247e5eb5 Mon Sep 17 00:00:00 2001 From: Cyril Gandon Date: Mon, 16 Oct 2017 15:48:16 +0200 Subject: [PATCH 1/5] member-access rule: check also for parameter property --- src/rules/memberAccessRule.ts | 19 ++++++++++++++----- test/rules/member-access/default/test.ts.fix | 12 ++++++++++++ test/rules/member-access/default/test.ts.lint | 13 +++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/rules/memberAccessRule.ts b/src/rules/memberAccessRule.ts index dc5fc1cc07a..547d7a72403 100644 --- a/src/rules/memberAccessRule.ts +++ b/src/rules/memberAccessRule.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { getChildOfKind, getModifier, getNextToken, getTokenAtPosition, isClassLikeDeclaration } from "tsutils"; +import { getChildOfKind, getModifier, getNextToken, getTokenAtPosition, isClassLikeDeclaration, isConstructorDeclaration } from "tsutils"; import * as ts from "typescript"; import { showWarningOnce } from "../error"; @@ -87,7 +87,7 @@ export class Rule extends Lint.Rules.AbstractRule { } function walk(ctx: Lint.WalkContext) { - const {noPublic, checkAccessor, checkConstructor} = ctx.options; + const { noPublic, checkAccessor, checkConstructor } = ctx.options; return ts.forEachChild(ctx.sourceFile, function recur(node: ts.Node): void { if (isClassLikeDeclaration(node)) { for (const child of node.members) { @@ -96,6 +96,13 @@ function walk(ctx: Lint.WalkContext) { } } } + if (isConstructorDeclaration(node)) { + for (const param of node.parameters) { + if (ts.isParameterPropertyDeclaration(param)) { + check(param); + } + } + } return ts.forEachChild(node, recur); }); @@ -114,7 +121,7 @@ function walk(ctx: Lint.WalkContext) { } } - function check(node: ts.ClassElement): void { + function check(node: ts.ClassElement | ts.ParameterDeclaration): void { if (Lint.hasModifier(node.modifiers, ts.SyntaxKind.ProtectedKeyword, ts.SyntaxKind.PrivateKeyword)) { return; } @@ -142,12 +149,12 @@ function walk(ctx: Lint.WalkContext) { } } -function getInsertionPosition(member: ts.ClassElement, sourceFile: ts.SourceFile): number { +function getInsertionPosition(member: ts.ClassElement | ts.ParameterDeclaration, sourceFile: ts.SourceFile): number { const node = member.decorators === undefined ? member : getTokenAtPosition(member, member.decorators.end, sourceFile)!; return node.getStart(sourceFile); } -function typeToString(node: ts.ClassElement): string { +function typeToString(node: ts.ClassElement | ts.ParameterDeclaration): string { switch (node.kind) { case ts.SyntaxKind.MethodDeclaration: return "class method"; @@ -159,6 +166,8 @@ function typeToString(node: ts.ClassElement): string { return "get property accessor"; case ts.SyntaxKind.SetAccessor: return "set property accessor"; + case ts.SyntaxKind.Parameter: + return "class parameter property"; default: throw new Error(`unhandled node type ${ts.SyntaxKind[node.kind]}`); } diff --git a/test/rules/member-access/default/test.ts.fix b/test/rules/member-access/default/test.ts.fix index 640a45fc5e9..70f92de4353 100644 --- a/test/rules/member-access/default/test.ts.fix +++ b/test/rules/member-access/default/test.ts.fix @@ -22,6 +22,18 @@ class Members { protected static nsProtected: number; private static nsPrivate: number; + constructor( + public readonly parameterPropertyR : number, + public parameterPropertyPublic : number, + protected parameterPropertyProtected : number, + private parameterPropertyPrivate : number, + public readonly parameterPropertyPublicR : number, + protected readonly parameterPropertyProtectedR : number, + private readonly parameterPropertyPrivateR : number + ){ + + } + public noAccess(x: number): number; public noAccess(o: any): any {} diff --git a/test/rules/member-access/default/test.ts.lint b/test/rules/member-access/default/test.ts.lint index 3f67fc4fa21..a4956383689 100644 --- a/test/rules/member-access/default/test.ts.lint +++ b/test/rules/member-access/default/test.ts.lint @@ -26,6 +26,19 @@ class Members { protected static nsProtected: number; private static nsPrivate: number; + constructor( + readonly parameterPropertyR : number, + ~~~~~~~~~~~~~~~~~~ [The class parameter property 'parameterPropertyR' must be marked either 'private', 'public', or 'protected'] + public parameterPropertyPublic : number, + protected parameterPropertyProtected : number, + private parameterPropertyPrivate : number, + public readonly parameterPropertyPublicR : number, + protected readonly parameterPropertyProtectedR : number, + private readonly parameterPropertyPrivateR : number + ){ + + } + noAccess(x: number): number; ~~~~~~~~ [The class method 'noAccess' must be marked either 'private', 'public', or 'protected'] noAccess(o: any): any {} From 1568dba35b82c3e41857963d13d4f6dce78edb72 Mon Sep 17 00:00:00 2001 From: Cyril Gandon Date: Mon, 16 Oct 2017 17:09:19 +0200 Subject: [PATCH 2/5] member-access rule: add test for no-public option --- src/rules/memberAccessRule.ts | 19 ++++++++++++------- .../rules/member-access/no-public/test.ts.fix | 2 ++ .../member-access/no-public/test.ts.lint | 3 +++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/rules/memberAccessRule.ts b/src/rules/memberAccessRule.ts index 547d7a72403..e8563f5ade9 100644 --- a/src/rules/memberAccessRule.ts +++ b/src/rules/memberAccessRule.ts @@ -127,13 +127,18 @@ function walk(ctx: Lint.WalkContext) { } const publicKeyword = getModifier(node, ts.SyntaxKind.PublicKeyword); if (noPublic && publicKeyword !== undefined) { - const start = publicKeyword.end - "public".length; - ctx.addFailure( - start, - publicKeyword.end, - Rule.FAILURE_STRING_NO_PUBLIC, - Lint.Replacement.deleteFromTo(start, getNextToken(publicKeyword, ctx.sourceFile)!.getStart(ctx.sourceFile)), - ); + const readonlyKeyword = getModifier(node, ts.SyntaxKind.ReadonlyKeyword); + // public is not optional for parameter property without the readonly modifier + const isPublicOptional = !ts.isParameterPropertyDeclaration(node) || readonlyKeyword !== undefined; + if (isPublicOptional) { + const start = publicKeyword.end - "public".length; + ctx.addFailure( + start, + publicKeyword.end, + Rule.FAILURE_STRING_NO_PUBLIC, + Lint.Replacement.deleteFromTo(start, getNextToken(publicKeyword, ctx.sourceFile)!.getStart(ctx.sourceFile)), + ); + } } if (!noPublic && publicKeyword === undefined) { const nameNode = node.kind === ts.SyntaxKind.Constructor diff --git a/test/rules/member-access/no-public/test.ts.fix b/test/rules/member-access/no-public/test.ts.fix index 7ce26d902a2..2dac767746e 100644 --- a/test/rules/member-access/no-public/test.ts.fix +++ b/test/rules/member-access/no-public/test.ts.fix @@ -3,5 +3,7 @@ class { constructor() {} get y() {} public() {} + constructor(readonly param : number) {} + constructor(public param : number) {} } diff --git a/test/rules/member-access/no-public/test.ts.lint b/test/rules/member-access/no-public/test.ts.lint index c7efc5642a2..e867a88a9c5 100644 --- a/test/rules/member-access/no-public/test.ts.lint +++ b/test/rules/member-access/no-public/test.ts.lint @@ -6,6 +6,9 @@ class { public/*some comment*/ get y() {} ~~~~~~ [0] public() {} + constructor(public readonly param : number) {} + ~~~~~~ [0] + constructor(public param : number) {} } [0]: 'public' is implicit. From ebce6603b993d7f7f148c660db73ec4bfee7d37c Mon Sep 17 00:00:00 2001 From: Cyril Gandon Date: Tue, 17 Oct 2017 09:15:01 +0200 Subject: [PATCH 3/5] member-access rule: add new-rule-option check-parameter-property --- src/configs/all.ts | 2 +- src/rules/memberAccessRule.ts | 47 ++++++++++--------- test/rules/member-access/default/test.ts.fix | 12 ----- test/rules/member-access/default/test.ts.lint | 13 ----- .../parameter-property/test.ts.fix | 13 +++++ .../parameter-property/test.ts.lint | 14 ++++++ .../parameter-property/tslint.json | 5 ++ 7 files changed, 59 insertions(+), 47 deletions(-) create mode 100644 test/rules/member-access/parameter-property/test.ts.fix create mode 100644 test/rules/member-access/parameter-property/test.ts.lint create mode 100644 test/rules/member-access/parameter-property/tslint.json diff --git a/src/configs/all.ts b/src/configs/all.ts index ec092781363..9b57f9f5fcf 100644 --- a/src/configs/all.ts +++ b/src/configs/all.ts @@ -36,7 +36,7 @@ export const rules = { ["Symbol", "Avoid using the `Symbol` type. Did you mean `symbol`?"], ], }, - "member-access": [true, "check-accessor", "check-constructor"], + "member-access": [true, "check-accessor", "check-constructor", "check-parameter-property"], "member-ordering": [true, { "order": "statics-first", "alphabetize": true, diff --git a/src/rules/memberAccessRule.ts b/src/rules/memberAccessRule.ts index e8563f5ade9..c454b06c2da 100644 --- a/src/rules/memberAccessRule.ts +++ b/src/rules/memberAccessRule.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { getChildOfKind, getModifier, getNextToken, getTokenAtPosition, isClassLikeDeclaration, isConstructorDeclaration } from "tsutils"; +import * as utils from "tsutils"; import * as ts from "typescript"; import { showWarningOnce } from "../error"; @@ -24,11 +24,13 @@ import * as Lint from "../index"; const OPTION_NO_PUBLIC = "no-public"; const OPTION_CHECK_ACCESSOR = "check-accessor"; const OPTION_CHECK_CONSTRUCTOR = "check-constructor"; +const OPTION_CHECK_PARAMETER_PROPERTY = "check-parameter-property"; interface Options { noPublic: boolean; checkAccessor: boolean; checkConstructor: boolean; + checkParameterProperty: boolean; } export class Rule extends Lint.Rules.AbstractRule { @@ -42,15 +44,16 @@ export class Rule extends Lint.Rules.AbstractRule { * \`"no-public"\` forbids public accessibility to be specified, because this is the default. * \`"check-accessor"\` enforces explicit visibility on get/set accessors - * \`"check-constructor"\` enforces explicit visibility on constructors`, + * \`"check-constructor"\` enforces explicit visibility on constructors + * \`"check-parameter-property"\` enforces explicit visibility on parameter properties`, options: { type: "array", items: { type: "string", - enum: [OPTION_NO_PUBLIC, OPTION_CHECK_ACCESSOR, OPTION_CHECK_CONSTRUCTOR], + enum: [OPTION_NO_PUBLIC, OPTION_CHECK_ACCESSOR, OPTION_CHECK_CONSTRUCTOR, OPTION_CHECK_PARAMETER_PROPERTY], }, minLength: 0, - maxLength: 3, + maxLength: 4, }, optionExamples: [true, [true, OPTION_NO_PUBLIC], [true, OPTION_CHECK_ACCESSOR]], type: "typescript", @@ -71,35 +74,37 @@ export class Rule extends Lint.Rules.AbstractRule { const noPublic = options.indexOf(OPTION_NO_PUBLIC) !== -1; let checkAccessor = options.indexOf(OPTION_CHECK_ACCESSOR) !== -1; let checkConstructor = options.indexOf(OPTION_CHECK_CONSTRUCTOR) !== -1; + let checkParameterProperty = options.indexOf(OPTION_CHECK_PARAMETER_PROPERTY) !== -1; if (noPublic) { - if (checkAccessor || checkConstructor) { + if (checkAccessor || checkConstructor || checkParameterProperty) { showWarningOnce(`Warning: ${this.ruleName} - If 'no-public' is present, it should be the only option.`); return []; } - checkAccessor = checkConstructor = true; + checkAccessor = checkConstructor = checkParameterProperty = true; } return this.applyWithFunction(sourceFile, walk, { checkAccessor, checkConstructor, + checkParameterProperty, noPublic, }); } } function walk(ctx: Lint.WalkContext) { - const { noPublic, checkAccessor, checkConstructor } = ctx.options; + const { noPublic, checkAccessor, checkConstructor, checkParameterProperty } = ctx.options; return ts.forEachChild(ctx.sourceFile, function recur(node: ts.Node): void { - if (isClassLikeDeclaration(node)) { + if (utils.isClassLikeDeclaration(node)) { for (const child of node.members) { if (shouldCheck(child)) { check(child); } - } - } - if (isConstructorDeclaration(node)) { - for (const param of node.parameters) { - if (ts.isParameterPropertyDeclaration(param)) { - check(param); + if (checkParameterProperty && utils.isConstructorDeclaration(child) && child.body !== undefined) { + for (const param of child.parameters) { + if (utils.isParameterProperty(param)) { + check(param); + } + } } } } @@ -125,24 +130,24 @@ function walk(ctx: Lint.WalkContext) { if (Lint.hasModifier(node.modifiers, ts.SyntaxKind.ProtectedKeyword, ts.SyntaxKind.PrivateKeyword)) { return; } - const publicKeyword = getModifier(node, ts.SyntaxKind.PublicKeyword); + const publicKeyword = utils.getModifier(node, ts.SyntaxKind.PublicKeyword); if (noPublic && publicKeyword !== undefined) { - const readonlyKeyword = getModifier(node, ts.SyntaxKind.ReadonlyKeyword); + const readonlyKeyword = utils.getModifier(node, ts.SyntaxKind.ReadonlyKeyword); // public is not optional for parameter property without the readonly modifier - const isPublicOptional = !ts.isParameterPropertyDeclaration(node) || readonlyKeyword !== undefined; + const isPublicOptional = node.kind !== ts.SyntaxKind.Parameter || readonlyKeyword !== undefined; if (isPublicOptional) { const start = publicKeyword.end - "public".length; ctx.addFailure( start, publicKeyword.end, Rule.FAILURE_STRING_NO_PUBLIC, - Lint.Replacement.deleteFromTo(start, getNextToken(publicKeyword, ctx.sourceFile)!.getStart(ctx.sourceFile)), + Lint.Replacement.deleteFromTo(start, utils.getNextToken(publicKeyword, ctx.sourceFile)!.getStart(ctx.sourceFile)), ); } } if (!noPublic && publicKeyword === undefined) { const nameNode = node.kind === ts.SyntaxKind.Constructor - ? getChildOfKind(node, ts.SyntaxKind.ConstructorKeyword, ctx.sourceFile)! + ? utils.getChildOfKind(node, ts.SyntaxKind.ConstructorKeyword, ctx.sourceFile)! : node.name !== undefined ? node.name : node; const memberName = node.name !== undefined && node.name.kind === ts.SyntaxKind.Identifier ? node.name.text : undefined; ctx.addFailureAtNode( @@ -155,7 +160,7 @@ function walk(ctx: Lint.WalkContext) { } function getInsertionPosition(member: ts.ClassElement | ts.ParameterDeclaration, sourceFile: ts.SourceFile): number { - const node = member.decorators === undefined ? member : getTokenAtPosition(member, member.decorators.end, sourceFile)!; + const node = member.decorators === undefined ? member : utils.getTokenAtPosition(member, member.decorators.end, sourceFile)!; return node.getStart(sourceFile); } @@ -172,7 +177,7 @@ function typeToString(node: ts.ClassElement | ts.ParameterDeclaration): string { case ts.SyntaxKind.SetAccessor: return "set property accessor"; case ts.SyntaxKind.Parameter: - return "class parameter property"; + return "parameter property"; default: throw new Error(`unhandled node type ${ts.SyntaxKind[node.kind]}`); } diff --git a/test/rules/member-access/default/test.ts.fix b/test/rules/member-access/default/test.ts.fix index 70f92de4353..640a45fc5e9 100644 --- a/test/rules/member-access/default/test.ts.fix +++ b/test/rules/member-access/default/test.ts.fix @@ -22,18 +22,6 @@ class Members { protected static nsProtected: number; private static nsPrivate: number; - constructor( - public readonly parameterPropertyR : number, - public parameterPropertyPublic : number, - protected parameterPropertyProtected : number, - private parameterPropertyPrivate : number, - public readonly parameterPropertyPublicR : number, - protected readonly parameterPropertyProtectedR : number, - private readonly parameterPropertyPrivateR : number - ){ - - } - public noAccess(x: number): number; public noAccess(o: any): any {} diff --git a/test/rules/member-access/default/test.ts.lint b/test/rules/member-access/default/test.ts.lint index a4956383689..3f67fc4fa21 100644 --- a/test/rules/member-access/default/test.ts.lint +++ b/test/rules/member-access/default/test.ts.lint @@ -26,19 +26,6 @@ class Members { protected static nsProtected: number; private static nsPrivate: number; - constructor( - readonly parameterPropertyR : number, - ~~~~~~~~~~~~~~~~~~ [The class parameter property 'parameterPropertyR' must be marked either 'private', 'public', or 'protected'] - public parameterPropertyPublic : number, - protected parameterPropertyProtected : number, - private parameterPropertyPrivate : number, - public readonly parameterPropertyPublicR : number, - protected readonly parameterPropertyProtectedR : number, - private readonly parameterPropertyPrivateR : number - ){ - - } - noAccess(x: number): number; ~~~~~~~~ [The class method 'noAccess' must be marked either 'private', 'public', or 'protected'] noAccess(o: any): any {} diff --git a/test/rules/member-access/parameter-property/test.ts.fix b/test/rules/member-access/parameter-property/test.ts.fix new file mode 100644 index 00000000000..09d598a8199 --- /dev/null +++ b/test/rules/member-access/parameter-property/test.ts.fix @@ -0,0 +1,13 @@ +class Members { + constructor( + public readonly parameterPropertyR : number, + public parameterPropertyPublic : number, + protected parameterPropertyProtected : number, + private parameterPropertyPrivate : number, + public readonly parameterPropertyPublicR : number, + protected readonly parameterPropertyProtectedR : number, + private readonly parameterPropertyPrivateR : number + ){ + + } +} diff --git a/test/rules/member-access/parameter-property/test.ts.lint b/test/rules/member-access/parameter-property/test.ts.lint new file mode 100644 index 00000000000..99838b17909 --- /dev/null +++ b/test/rules/member-access/parameter-property/test.ts.lint @@ -0,0 +1,14 @@ +class Members { + constructor( + readonly parameterPropertyR : number, + ~~~~~~~~~~~~~~~~~~ [The parameter property 'parameterPropertyR' must be marked either 'private', 'public', or 'protected'] + public parameterPropertyPublic : number, + protected parameterPropertyProtected : number, + private parameterPropertyPrivate : number, + public readonly parameterPropertyPublicR : number, + protected readonly parameterPropertyProtectedR : number, + private readonly parameterPropertyPrivateR : number + ){ + + } +} diff --git a/test/rules/member-access/parameter-property/tslint.json b/test/rules/member-access/parameter-property/tslint.json new file mode 100644 index 00000000000..d4c6243e573 --- /dev/null +++ b/test/rules/member-access/parameter-property/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "member-access": [true, "check-parameter-property"] + } +} From 6087fe86e14093dedc5d36420169b0a600118242 Mon Sep 17 00:00:00 2001 From: Cyril Gandon Date: Wed, 18 Oct 2017 09:05:01 +0200 Subject: [PATCH 4/5] memberAccessRule: prefer multiline import to namespace import --- src/rules/memberAccessRule.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/rules/memberAccessRule.ts b/src/rules/memberAccessRule.ts index c454b06c2da..254262ff145 100644 --- a/src/rules/memberAccessRule.ts +++ b/src/rules/memberAccessRule.ts @@ -15,7 +15,15 @@ * limitations under the License. */ -import * as utils from "tsutils"; +import { + getChildOfKind, + getModifier, + getNextToken, + getTokenAtPosition, + isClassLikeDeclaration, + isConstructorDeclaration, + isParameterProperty, +} from "tsutils"; import * as ts from "typescript"; import { showWarningOnce } from "../error"; @@ -94,14 +102,14 @@ export class Rule extends Lint.Rules.AbstractRule { function walk(ctx: Lint.WalkContext) { const { noPublic, checkAccessor, checkConstructor, checkParameterProperty } = ctx.options; return ts.forEachChild(ctx.sourceFile, function recur(node: ts.Node): void { - if (utils.isClassLikeDeclaration(node)) { + if (isClassLikeDeclaration(node)) { for (const child of node.members) { if (shouldCheck(child)) { check(child); } - if (checkParameterProperty && utils.isConstructorDeclaration(child) && child.body !== undefined) { + if (checkParameterProperty && isConstructorDeclaration(child) && child.body !== undefined) { for (const param of child.parameters) { - if (utils.isParameterProperty(param)) { + if (isParameterProperty(param)) { check(param); } } @@ -130,9 +138,9 @@ function walk(ctx: Lint.WalkContext) { if (Lint.hasModifier(node.modifiers, ts.SyntaxKind.ProtectedKeyword, ts.SyntaxKind.PrivateKeyword)) { return; } - const publicKeyword = utils.getModifier(node, ts.SyntaxKind.PublicKeyword); + const publicKeyword = getModifier(node, ts.SyntaxKind.PublicKeyword); if (noPublic && publicKeyword !== undefined) { - const readonlyKeyword = utils.getModifier(node, ts.SyntaxKind.ReadonlyKeyword); + const readonlyKeyword = getModifier(node, ts.SyntaxKind.ReadonlyKeyword); // public is not optional for parameter property without the readonly modifier const isPublicOptional = node.kind !== ts.SyntaxKind.Parameter || readonlyKeyword !== undefined; if (isPublicOptional) { @@ -141,13 +149,13 @@ function walk(ctx: Lint.WalkContext) { start, publicKeyword.end, Rule.FAILURE_STRING_NO_PUBLIC, - Lint.Replacement.deleteFromTo(start, utils.getNextToken(publicKeyword, ctx.sourceFile)!.getStart(ctx.sourceFile)), + Lint.Replacement.deleteFromTo(start, getNextToken(publicKeyword, ctx.sourceFile)!.getStart(ctx.sourceFile)), ); } } if (!noPublic && publicKeyword === undefined) { const nameNode = node.kind === ts.SyntaxKind.Constructor - ? utils.getChildOfKind(node, ts.SyntaxKind.ConstructorKeyword, ctx.sourceFile)! + ? getChildOfKind(node, ts.SyntaxKind.ConstructorKeyword, ctx.sourceFile)! : node.name !== undefined ? node.name : node; const memberName = node.name !== undefined && node.name.kind === ts.SyntaxKind.Identifier ? node.name.text : undefined; ctx.addFailureAtNode( @@ -160,7 +168,7 @@ function walk(ctx: Lint.WalkContext) { } function getInsertionPosition(member: ts.ClassElement | ts.ParameterDeclaration, sourceFile: ts.SourceFile): number { - const node = member.decorators === undefined ? member : utils.getTokenAtPosition(member, member.decorators.end, sourceFile)!; + const node = member.decorators === undefined ? member : getTokenAtPosition(member, member.decorators.end, sourceFile)!; return node.getStart(sourceFile); } From e5c4358771ecf9dfc9adc65d1970173b5584c7fa Mon Sep 17 00:00:00 2001 From: Cyril Gandon Date: Wed, 18 Oct 2017 09:05:46 +0200 Subject: [PATCH 5/5] memberAccessRule: add more tests --- docs/_data/formatters.json | 2 +- docs/formatters/stylish/index.html | 4 ++-- .../rules/member-access/no-public/test.ts.fix | 5 ++++- .../member-access/no-public/test.ts.lint | 7 +++++- .../parameter-property/test.ts.fix | 18 +++++++++------ .../parameter-property/test.ts.lint | 22 ++++++++++++------- 6 files changed, 38 insertions(+), 20 deletions(-) diff --git a/docs/_data/formatters.json b/docs/_data/formatters.json index 53730f41ede..d2acb3beedf 100644 --- a/docs/_data/formatters.json +++ b/docs/_data/formatters.json @@ -55,7 +55,7 @@ { "formatterName": "stylish", "description": "Human-readable formatter which creates stylish messages.", - "descriptionDetails": "\nThe output matches that produced by eslint's stylish formatter. Its readability\nenhanced through spacing and colouring", + "descriptionDetails": "\nThe output matches what is produced by ESLint's stylish formatter.\nIts readability is enhanced through spacing and colouring.", "sample": "\nmyFile.ts\n1:14 semicolon Missing semicolon", "consumer": "human" }, diff --git a/docs/formatters/stylish/index.html b/docs/formatters/stylish/index.html index aae4d9f997e..0680cc252f0 100644 --- a/docs/formatters/stylish/index.html +++ b/docs/formatters/stylish/index.html @@ -3,8 +3,8 @@ description: Human-readable formatter which creates stylish messages. descriptionDetails: |- - The output matches that produced by eslint's stylish formatter. Its readability - enhanced through spacing and colouring + The output matches what is produced by ESLint's stylish formatter. + Its readability is enhanced through spacing and colouring. sample: |- myFile.ts diff --git a/test/rules/member-access/no-public/test.ts.fix b/test/rules/member-access/no-public/test.ts.fix index 2dac767746e..25f61ce9e3a 100644 --- a/test/rules/member-access/no-public/test.ts.fix +++ b/test/rules/member-access/no-public/test.ts.fix @@ -4,6 +4,9 @@ class { get y() {} public() {} constructor(readonly param : number) {} - constructor(public param : number) {} + constructor(readonly param : number) {} + constructor(private readonly paramPrivate : number, protected readonly paramProtected : number, readonly paramReadonly : number) {} + + constructor(public necessaryPublic : number) {} } diff --git a/test/rules/member-access/no-public/test.ts.lint b/test/rules/member-access/no-public/test.ts.lint index e867a88a9c5..138f6d73841 100644 --- a/test/rules/member-access/no-public/test.ts.lint +++ b/test/rules/member-access/no-public/test.ts.lint @@ -8,7 +8,12 @@ class { public() {} constructor(public readonly param : number) {} ~~~~~~ [0] - constructor(public param : number) {} + public constructor(public readonly param : number) {} + ~~~~~~ [0] + ~~~~~~ [0] + constructor(private readonly paramPrivate : number, protected readonly paramProtected : number, readonly paramReadonly : number) {} + + constructor(public necessaryPublic : number) {} } [0]: 'public' is implicit. diff --git a/test/rules/member-access/parameter-property/test.ts.fix b/test/rules/member-access/parameter-property/test.ts.fix index 09d598a8199..889981a518c 100644 --- a/test/rules/member-access/parameter-property/test.ts.fix +++ b/test/rules/member-access/parameter-property/test.ts.fix @@ -1,13 +1,17 @@ class Members { constructor( - public readonly parameterPropertyR : number, - public parameterPropertyPublic : number, - protected parameterPropertyProtected : number, - private parameterPropertyPrivate : number, - public readonly parameterPropertyPublicR : number, - protected readonly parameterPropertyProtectedR : number, - private readonly parameterPropertyPrivateR : number + public readonly paramReadonly : number, + public paramPublic : number, + protected paramProtected : number, + private paramPrivate : number, + public readonly paramPublicReadonly : number, + protected readonly paramProtectedReadonly : number, + private readonly paramPrivateReadonly : number ){ } + + constructor(public readonly a : number, @decorated public readonly b : number) { + + } } diff --git a/test/rules/member-access/parameter-property/test.ts.lint b/test/rules/member-access/parameter-property/test.ts.lint index 99838b17909..2c110ca7a31 100644 --- a/test/rules/member-access/parameter-property/test.ts.lint +++ b/test/rules/member-access/parameter-property/test.ts.lint @@ -1,14 +1,20 @@ class Members { constructor( - readonly parameterPropertyR : number, - ~~~~~~~~~~~~~~~~~~ [The parameter property 'parameterPropertyR' must be marked either 'private', 'public', or 'protected'] - public parameterPropertyPublic : number, - protected parameterPropertyProtected : number, - private parameterPropertyPrivate : number, - public readonly parameterPropertyPublicR : number, - protected readonly parameterPropertyProtectedR : number, - private readonly parameterPropertyPrivateR : number + readonly paramReadonly : number, + ~~~~~~~~~~~~~ [The parameter property 'paramReadonly' must be marked either 'private', 'public', or 'protected'] + public paramPublic : number, + protected paramProtected : number, + private paramPrivate : number, + public readonly paramPublicReadonly : number, + protected readonly paramProtectedReadonly : number, + private readonly paramPrivateReadonly : number ){ } + + constructor(readonly a : number, @decorated readonly b : number) { + ~ [The parameter property 'a' must be marked either 'private', 'public', or 'protected'] + ~ [The parameter property 'b' must be marked either 'private', 'public', or 'protected'] + + } }