Skip to content

Commit 54a62c9

Browse files
committed
refactor: Rename dir to dirPath
1 parent a8e6a18 commit 54a62c9

4 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/generate/action.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ export function moveRenamePath(oldPath: string, newPath: string): string {
4141
newP = splitPath(newPath);
4242

4343
if (oldP.name === newP.name) {
44-
const target = newP.dir;
44+
const target = newP.dirPath;
4545
return `Move ${oldP.name} to ${target}`;
4646
}
47-
if (oldP.dir === newP.dir) {
47+
if (oldP.dirPath === newP.dirPath) {
4848
const target = newP.name;
4949
return `Rename ${oldP.name} to ${target}`;
5050
}
5151

52-
const target = newP.dir === ROOT ? `${newP.name} at ${ROOT}` : newPath;
52+
const target = newP.dirPath === ROOT ? `${newP.name} at ${ROOT}` : newPath;
5353
return `Move and rename ${oldP.name} to ${target}`;
5454
}

src/generate/paths.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ROOT } from './constants';
99

1010
interface SplitPathResult {
1111
atRoot: boolean;
12-
dir: string;
12+
dirPath: string;
1313
name: string;
1414
extension: string;
1515
}
@@ -30,7 +30,7 @@ export function splitPath(filePath: string): SplitPathResult {
3030

3131
return {
3232
atRoot: isAtRepoRoot,
33-
dir: isAtRepoRoot ? ROOT : dir,
33+
dirPath: isAtRepoRoot ? ROOT : dir,
3434
name: path.basename(filePath),
3535
extension: path.extname(filePath)
3636
};

src/generate/semantic.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const PACKAGE_NAMES = [
4343
*/
4444
export class Semantic {
4545
atRoot: boolean;
46-
dir: string;
46+
dirPath: string;
4747
name: string;
4848
extension: string;
4949

@@ -55,9 +55,9 @@ export class Semantic {
5555
// Maybe a class is overkill as it is just a container of data.
5656
// Maybe the {} can be stored an object here. Or maybe combine that and this at the risk
5757
// of doing too much. But still easy to test attributes vs methods.
58-
const { atRoot, dir, name, extension } = splitPath(filePath);
58+
const { atRoot, dirPath, name, extension } = splitPath(filePath);
5959
this.atRoot = atRoot;
60-
this.dir = dir;
60+
this.dirPath = dirPath;
6161
this.name = name;
6262
this.extension = extension;
6363
}
@@ -69,12 +69,12 @@ export class Semantic {
6969
* except perhaps for config files.
7070
*/
7171
isDocRelated(): boolean {
72-
return this.name === 'README.md' || this.dir.startsWith('docs');
72+
return this.name === 'README.md' || this.dirPath.startsWith('docs');
7373
}
7474

7575
isTestRelated(): boolean {
7676
return (
77-
this.dir.includes('test/') ||
77+
this.dirPath.includes('test/') ||
7878
this.name.includes('.test.') ||
7979
this.name.includes('.spec.') ||
8080
this.name.startsWith('test_') ||
@@ -83,15 +83,15 @@ export class Semantic {
8383
}
8484

8585
isCIRelated(): boolean {
86-
return this.dir in CI_DIRS || this.name in CI_NAMES;
86+
return this.dirPath in CI_DIRS || this.name in CI_NAMES;
8787
}
8888

8989
// Broadly match eslint configs https://eslint.org/docs/user-guide/configuring
9090
// And prettier configs https://prettier.io/docs/en/configuration.html
9191
isConfigRelated(): boolean {
9292
if (
9393
this.extension in CONFIG_EXTENSIONS ||
94-
this.dir in CONFIG_DIRS ||
94+
this.dirPath in CONFIG_DIRS ||
9595
this.name in CONFIG_NAMES ||
9696
this.name.includes('.eslintrc') ||
9797
this.name.includes('.prettier')

src/test/paths.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ describe('Path handling', function() {
77
it('splits a path correctly', function() {
88
assert.deepEqual(splitPath('baz.txt'), {
99
atRoot: true,
10-
dir: 'repo root',
10+
dirPath: 'repo root',
1111
name: 'baz.txt',
1212
extension: '.txt'
1313
});
1414

1515
assert.deepEqual(splitPath('foo/bar/baz.txt'), {
1616
atRoot: false,
17-
dir: 'foo/bar',
17+
dirPath: 'foo/bar',
1818
name: 'baz.txt',
1919
extension: '.txt'
2020
});

0 commit comments

Comments
 (0)