Skip to content

Improve name validation with component schematic (and others)  #13824

Closed
@yjaaidi

Description

@yjaaidi

🚀 Feature request

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [X] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Description

A clear and concise description of the problem or missing capability...

Using dots in component name when using component schematic (might also happen with other schematics) should fail. I.e. ng generate component a.b.x should fail.

I noticed that people who are new to Angular tend to use the schematic like this for the first time:

ng generate component hello-world.component

which produces something funky like this:

export class HelloWorld.ComponentComponent

Describe the solution you'd like

If you have a solution in mind, please describe it.

Use some whitelist regex to check the component's name before.

By the way, why does the component's selector allow dots in the regular expression below?

export const htmlSelectorRe = /^[a-zA-Z][.0-9a-zA-Z]*(:?-[a-zA-Z][.0-9a-zA-Z]*)*$/;

Describe alternatives you've considered

Have you considered any alternative solutions or workarounds?
ng generate component hello-world.component
echo D'OH!
git reset --hard
git clean -d -f
ng generate component hello-world

Anyway, I am in for a pull request.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions