Skip to content

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

Closed

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.

Activity

  1. alan-agius4 commented on Mar 6, 2019

    @alan-agius4
    Collaborator

    This also relates to #12868

    I am not sure why a dot is allowed there, maybe @clydin knows.

  2. added this to the needsTriage milestone on Mar 6, 2019
  3. clydin commented on Mar 6, 2019

    @clydin
    Member

    It's a valid character in an HTML element name. That regex is technically overly restrictive as well. unicode characters should be allowed.

  4. modified the milestones: needsTriage, Backlog on May 25, 2020
  5. dgp1130 commented on May 30, 2020

    @dgp1130
    Collaborator

    Should we dupe this against #11051? That one has to do with ng new while this has to do with ng generate, but they are both schematics related and likely have the same root cause?

  6. alan-agius4 commented on May 30, 2020

    @alan-agius4
    Collaborator

    @dgp1130, I think it’s best to keep these separate since this is a separate validate pattern. Unless we want to create a new master issue to track various validation issues.

  7. added a commit that references this issue on Jul 1, 2022
    06eb4aa
  8. added a commit that references this issue on Jul 21, 2022
    7212493
  9. added 2 commits that reference this issue on Jul 21, 2022
    e63375e
    44c1808
  10. angular-automatic-lock-bot commented on Aug 21, 2022

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  11. locked and limited conversation to collaborators on Aug 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions