This repository has been archived by the owner on Dec 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implements fixer for
import-barrels
and according tests
- Loading branch information
1 parent
937625d
commit 5a89bf4
Showing
31 changed files
with
162 additions
and
92 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
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
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 @@ | ||
import relativeFromNonBarrel from './dir-with-barrel'; | ||
import relativeFromNonBarrelWithIndexLikeName from './dir-with-barrel'; | ||
|
||
// following should be OK | ||
import relativeFromBarrel from './dir-with-barrel'; | ||
import relativeFromBarrelExplicit from './dir-with-barrel/index'; | ||
import relativeFromDirWithoutBarrel from './dir-without-barrel/some-module'; | ||
import relativeFromSameDirWithBarrel from './some-module'; | ||
import relativeFromSameDirWithBarrelExplicit from './index'; | ||
import absoluteFromLib from 'lib'; |
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
Empty file.
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions
2
src/tests/importBarrels/fixWithExplicitBarrelImport/fixWithExplicitBarrelImport.ts.fix
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,2 @@ | ||
import relativeFromNonBarrel from './dir-with-barrel/index.ts'; | ||
import relativeFromNonBarrelWithIndexLikeName from './dir-with-barrel/index.ts'; |
4 changes: 4 additions & 0 deletions
4
src/tests/importBarrels/fixWithExplicitBarrelImport/fixWithExplicitBarrelImport.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,4 @@ | ||
import relativeFromNonBarrel from './dir-with-barrel/some-module'; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Use barrel (index) files for imports if they are available for path: './dir-with-barrel/some-module'] | ||
import relativeFromNonBarrelWithIndexLikeName from './dir-with-barrel/some-module-index'; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Use barrel (index) files for imports if they are available for path: './dir-with-barrel/some-module-index'] |
13 changes: 13 additions & 0 deletions
13
src/tests/importBarrels/fixWithExplicitBarrelImport/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,13 @@ | ||
{ | ||
"rulesDirectory": [ | ||
"../../../../dist" | ||
], | ||
"rules": { | ||
"import-barrels": [ | ||
true, | ||
{ | ||
"fixWithExplicitBarrelImport": "index.ts" | ||
} | ||
] | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/tests/importBarrels/no-explicit-barrels/noExplicitBarrels.ts.fix
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,5 @@ | ||
import relativeFromBarrelExplicit from './dir-with-barrel'; | ||
|
||
// following should be OK | ||
import relativeFromBarrel from './dir-with-barrel'; | ||
import relativeFromNonBarrelWithIndexLikeName from './dir-without-barrel/some-module-index'; |
1 change: 1 addition & 0 deletions
1
...mportBarrelRulesNoExplicitBarrels.ts.lint → ...xplicit-barrels/noExplicitBarrels.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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import relativeFromBarrelExplicit from './dir-with-barrel/index'; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~ [Don't import barrel files by name, import containing directory instead for path: './dir-with-barrel/index'] | ||
|
||
// following should be OK | ||
import relativeFromBarrel from './dir-with-barrel'; | ||
import relativeFromNonBarrelWithIndexLikeName from './dir-without-barrel/some-module-index'; |
4 changes: 4 additions & 0 deletions
4
src/tests/importBarrels/with-extension-list/withExtensionList.ts.fix
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,4 @@ | ||
import relativeFromNonBarrel from './dir-with-barrel'; | ||
|
||
// following should be OK | ||
import relativeFromNonBarrelWithIndexName from './dir-with-barrel/some-module-index'; |
2 changes: 2 additions & 0 deletions
2
...mportBarrelRulesWithExtensionList.ts.lint → ...-extension-list/withExtensionList.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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import relativeFromNonBarrel from './dir-with-barrel/some-module'; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Use barrel (index) files for imports if they are available for path: './dir-with-barrel/some-module'] | ||
|
||
// following should be OK | ||
import relativeFromNonBarrelWithIndexName from './dir-with-barrel/some-module-index'; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,30 @@ | ||
import * as fs from 'fs'; | ||
|
||
export class CachedStat { | ||
private readonly statCache = new Map<string, fs.Stats>(); | ||
|
||
public statSync(path:string):fs.Stats|null { | ||
if (this.statCache.has(path)) { | ||
return <fs.Stats>this.statCache.get(path); | ||
} | ||
|
||
const stat = this.statSyncUncached(path); | ||
if (stat !== null) { | ||
this.statCache.set(path, stat); | ||
} | ||
return stat; | ||
} | ||
|
||
public isFile(path:string):boolean { | ||
const stats = this.statSync(path); | ||
return stats != null && stats.isFile(); | ||
} | ||
|
||
private statSyncUncached(path:string):fs.Stats|null { | ||
try { | ||
return fs.statSync(path); | ||
} catch (e) { | ||
return null; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.