This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 889
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[complete-doc]: add support for constuctor doc (#4861)
* [complete-doc]: add support for constuctor doc * [complete-docs]: add test for protected constructor, fix class name
- Loading branch information
1 parent
bfaf3e2
commit e493270
Showing
11 changed files
with
358 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* @license | ||
* Copyright 2019 Palantir Technologies, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { hasModifier } from "tsutils"; | ||
import * as ts from "typescript"; | ||
|
||
import { | ||
ALL, | ||
Privacy, | ||
PRIVACY_PRIVATE, | ||
PRIVACY_PROTECTED, | ||
PRIVACY_PUBLIC, | ||
} from "../completedDocsRule"; | ||
|
||
import { Exclusion } from "./exclusion"; | ||
|
||
export interface IConstructorExclusionDescriptor { | ||
privacies?: Privacy[]; | ||
} | ||
|
||
export class ConstructorExclusion extends Exclusion<IConstructorExclusionDescriptor> { | ||
public readonly privacies: Set<Privacy> = this.createSet(this.descriptor.privacies); | ||
|
||
public excludes(node: ts.Node) { | ||
if (this.privacies.has(ALL)) { | ||
return false; | ||
} | ||
|
||
if (hasModifier(node.modifiers, ts.SyntaxKind.PrivateKeyword)) { | ||
return !this.privacies.has(PRIVACY_PRIVATE); | ||
} | ||
|
||
if (hasModifier(node.modifiers, ts.SyntaxKind.ProtectedKeyword)) { | ||
return !this.privacies.has(PRIVACY_PROTECTED); | ||
} | ||
|
||
return !this.privacies.has(PRIVACY_PUBLIC); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
test/rules/completed-docs/constructors/overloads/default/test.ts.lint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class Foo { | ||
constructor(i: number); | ||
|
||
/** | ||
* Exists in one place | ||
*/ | ||
constructor(o: any) {} | ||
} | ||
|
||
class FooPublic { | ||
public constructor(i: number); | ||
|
||
/** | ||
* Exists in one place | ||
*/ | ||
public constructor(o: any) {} | ||
} | ||
|
||
class FooPrivate { | ||
private constructor(i: number); | ||
|
||
/** | ||
* Exists in one place | ||
*/ | ||
private constructor(o: any) {} | ||
} | ||
|
||
class FooProtected { | ||
protected constructor(i: number); | ||
protected constructor(o: any) {} | ||
} |
9 changes: 9 additions & 0 deletions
9
test/rules/completed-docs/constructors/overloads/default/tslint.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"rules": { | ||
"completed-docs": [true, { | ||
"constructors": { | ||
"privacies": ["public", "private"] | ||
} | ||
}] | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
test/rules/completed-docs/constructors/overloads/true/test.ts.lint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class Foo { | ||
constructor(i: number); | ||
~~~~~~~~~~~~~~~~~~~~~~~ [default] | ||
/** | ||
* Exists in one place | ||
*/ | ||
constructor(o: any) {} | ||
} | ||
|
||
class FooPublic { | ||
public constructor(i: number); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [public] | ||
/** | ||
* Exists in one place | ||
*/ | ||
public constructor(o: any) {} | ||
} | ||
|
||
class FooPrivate { | ||
private constructor(i: number); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [private] | ||
/** | ||
* Exists in one place | ||
*/ | ||
private constructor(o: any) {} | ||
} | ||
|
||
class FooProtected { | ||
protected constructor(i: number); | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [protected] | ||
/** | ||
* Exists in one place | ||
*/ | ||
protected constructor(o: any) {} | ||
} | ||
|
||
[default]: Documentation must exist for constructors. | ||
[public]: Documentation must exist for public constructors. | ||
[private]: Documentation must exist for private constructors. | ||
[protected]: Documentation must exist for protected constructors. |
10 changes: 10 additions & 0 deletions
10
test/rules/completed-docs/constructors/overloads/true/tslint.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"rules": { | ||
"completed-docs": [true, { | ||
"constructors": { | ||
"overloads": true, | ||
"privacies": ["public", "protected", "private"] | ||
} | ||
}] | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
test/rules/completed-docs/constructors/privacies/test.ts.lint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
class Foo { | ||
constructor() {} | ||
~~~~~~~~~~~~~~~~ [default] | ||
} | ||
|
||
class Foo { | ||
public constructor() {} | ||
~~~~~~~~~~~~~~~~~~~~~~~ [public] | ||
} | ||
|
||
class Foo { | ||
private constructor() {} | ||
~~~~~~~~~~~~~~~~~~~~~~~~ [private] | ||
} | ||
|
||
class Foo { | ||
protected constructor() {} | ||
} | ||
|
||
class Foo { | ||
/** ... */ | ||
constructor() {} | ||
} | ||
|
||
class Foo { | ||
/** content */ | ||
constructor() {} | ||
} | ||
|
||
class Foo { | ||
/** */ | ||
constructor() {} | ||
~~~~~~~~~~~~~~~~ [default] | ||
} | ||
|
||
class Foo { | ||
/** ... */ | ||
public constructor() {} | ||
} | ||
|
||
class Foo { | ||
/** content */ | ||
public constructor() {} | ||
} | ||
|
||
class Foo { | ||
/** */ | ||
public constructor() {} | ||
~~~~~~~~~~~~~~~~~~~~~~~ [public] | ||
} | ||
|
||
class Foo { | ||
/** ... */ | ||
private constructor() {} | ||
} | ||
|
||
class Foo { | ||
/** content */ | ||
private constructor() {} | ||
} | ||
|
||
class Foo { | ||
/** */ | ||
private constructor() {} | ||
~~~~~~~~~~~~~~~~~~~~~~~~ [private] | ||
} | ||
|
||
|
||
class Foo { | ||
/** | ||
* ... | ||
*/ | ||
constructor() {} | ||
} | ||
|
||
class Foo { | ||
/** | ||
* ... | ||
*/ | ||
public constructor() {} | ||
} | ||
|
||
class Foo { | ||
/** | ||
* ... | ||
*/ | ||
private constructor() {} | ||
} | ||
|
||
class Foo { | ||
/** | ||
* ... | ||
*/ | ||
protected constructor() {} | ||
} | ||
|
||
[default]: Documentation must exist for constructors. | ||
[public]: Documentation must exist for public constructors. | ||
[private]: Documentation must exist for private constructors. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"rules": { | ||
"completed-docs": [true, { | ||
"constructors": { | ||
"privacies": ["public", "private"] | ||
} | ||
}] | ||
} | ||
} |
Oops, something went wrong.