Skip to content

Commit

Permalink
fix(devkit): don't replace begining undescore when creating file (nrw…
Browse files Browse the repository at this point in the history
…l#9870)

Underscore is a character usually used for sorting purposes and is absolutely legit. There is no
reason to replace it.

ISSUES CLOSED: nrwl#8875
  • Loading branch information
AloisH authored and jaytavares committed Jun 8, 2022
1 parent edea1f2 commit 2ae5bdb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/devkit/src/utils/names.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ describe('names', () => {
expect(names('[fooBar]').className).toEqual('FooBar');
expect(names('[...fooBar]').className).toEqual('FooBar');
expect(names('foo-@bar').className).toEqual('FooBar');
expect(names(' foo bar').className).toEqual('FooBar');
expect(names('_foo_bar').className).toEqual('FooBar');
});

it('should support property names', () => {
Expand All @@ -17,6 +19,8 @@ describe('names', () => {
expect(names('[fooBar]').propertyName).toEqual('fooBar');
expect(names('[...fooBar]').propertyName).toEqual('fooBar');
expect(names('foo-@bar').propertyName).toEqual('fooBar');
expect(names(' foo bar').propertyName).toEqual('fooBar');
expect(names('_foo_bar').propertyName).toEqual('fooBar');
});

it('should support file names', () => {
Expand All @@ -26,5 +30,7 @@ describe('names', () => {
expect(names('[fooBar]').fileName).toEqual('[foo-bar]');
expect(names('[...fooBar]').fileName).toEqual('[...foo-bar]');
expect(names('foo-@bar').fileName).toEqual('foo-@bar');
expect(names(' foo bar').fileName).toEqual('-foo-bar');
expect(names('_foo_bar').fileName).toEqual('_foo-bar');
});
});
2 changes: 1 addition & 1 deletion packages/devkit/src/utils/names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function toFileName(s: string): string {
return s
.replace(/([a-z\d])([A-Z])/g, '$1_$2')
.toLowerCase()
.replace(/[ _]/g, '-');
.replace(/(?!^[_])[ _]/g, '-');
}

/**
Expand Down

0 comments on commit 2ae5bdb

Please sign in to comment.