-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
122 additions
and
5 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
declare namespace Foo1 { | ||
export function foo(s: string): void; | ||
export function foo(n: number): void; | ||
export function bar(): void; | ||
export function foo(sn: string | number): void; | ||
} | ||
|
||
type Foo2 = { | ||
foo(s: string): void; | ||
foo(n: number): void; | ||
bar(): void; | ||
foo(sn: string | number): void; | ||
}; | ||
|
||
interface Foo3 { | ||
foo(s: string): void; | ||
foo(n: number): void; | ||
bar(): void; | ||
foo(sn: string | number): void; | ||
} |
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,20 @@ | ||
declare namespace Foo1 { | ||
export function foo(s: string): void; | ||
export function foo(n: number): void; | ||
export function foo(sn: string | number): void; | ||
export function bar(): void; | ||
} | ||
|
||
type Foo4 = { | ||
foo(s: string): void; | ||
foo(n: number): void; | ||
foo(sn: string | number): void; | ||
bar(): void; | ||
}; | ||
|
||
interface Foo3 { | ||
foo(s: string): void; | ||
foo(n: number): void; | ||
foo(sn: string | number): void; | ||
bar(): void; | ||
} |
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 @@ | ||
{} |
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": { | ||
"adjacent-overload-signatures": true | ||
}, | ||
"meta": { | ||
"description": "定义函数时如果用到了覆写,则必须将覆写的函数写到一起", | ||
"ts-only": true | ||
} | ||
} |
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,64 @@ | ||
import * as assert from 'assert'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
|
||
import { Linter } from 'tslint'; | ||
import { parseConfigFile } from 'tslint/lib/configuration'; | ||
|
||
const testNameList = fs | ||
.readdirSync(__dirname) | ||
.filter((filename) => | ||
fs.lstatSync(path.resolve(__dirname, filename)).isDirectory(), | ||
); | ||
|
||
describe('TSLint rules', () => { | ||
testNameList.forEach((testName) => { | ||
describe(testName, () => { | ||
it('should have lint error for bad.ts', () => { | ||
const linter = new Linter({ | ||
fix: false, | ||
}); | ||
linter.lint( | ||
`./${testName}/bad.ts`, | ||
fs.readFileSync( | ||
path.resolve(__dirname, `./${testName}/bad.ts`), | ||
'utf-8', | ||
), | ||
parseConfigFile(require(`./${testName}/tslint.json`)), | ||
); | ||
const lintResult = linter.getResult(); | ||
assert.ok( | ||
lintResult.errorCount > 0, | ||
'Does not have lint error', | ||
); | ||
lintResult.failures.forEach((failure) => { | ||
const failedRuleName = failure.getRuleName(); | ||
assert.equal( | ||
failedRuleName, | ||
testName, | ||
`Failed rule '${failedRuleName}' does not match '${testName}'`, | ||
); | ||
}); | ||
}); | ||
it('should pass the lint for good.ts', () => { | ||
const linter = new Linter({ | ||
fix: false, | ||
}); | ||
linter.lint( | ||
`./${testName}/good.ts`, | ||
fs.readFileSync( | ||
path.resolve(__dirname, `./${testName}/good.ts`), | ||
'utf-8', | ||
), | ||
parseConfigFile(require(`./${testName}/tslint.json`)), | ||
); | ||
const lintResult = linter.getResult(); | ||
assert.equal( | ||
lintResult.errorCount, | ||
0, | ||
'Have at least one error', | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |