Skip to content

Conversation

harshlakhara
Copy link

@harshlakhara harshlakhara commented Oct 2, 2024

fix(@schematics/angular): add validation for component and directive class name

class names for directives and components when they are created using ng generate component <className>
added tests for the changes made above

PR Checklist

Please check to confirm your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #28548

What is the new behavior?

When a component or directive is created using an invalid character, such as a class name that begins with a number or a component or directive name that contains only a number, cli will throw an error.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Copy link
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution.

Can you please change the commit message scope from @angular/cli to @schematics/angular please?

@alan-agius4 alan-agius4 added the target: patch This PR is targeted for the next patch release label Oct 2, 2024
@alan-agius4 alan-agius4 added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Oct 2, 2024
@harshlakhara harshlakhara changed the title fix(@angular/cli): add validation for component and directive class name fix(@schematics/angular): add validation for component and directive class name Oct 2, 2024
@harshlakhara
Copy link
Author

@alan-agius4 I have updated the scope to @schematics/angular

@alan-agius4
Copy link
Collaborator

@alan-agius4 I have updated the scope to @schematics/angular

Please update the commit message and not the PR title, also one of the tests appear to be failing;

Failures:
1) Component Schematic standalone=false should error when class name contains invalid characters
  Message:
    Expected a promise to be rejected with Error: 'Class name "1Clazz" is invalid.' but it was rejected with Error: Selector "app-1-clazz" is invalid..
  Stack:
        at <Jasmine>
        at UserContext.<anonymous> (packages/schematics/angular/component/index_spec.ts:504:9)
        at <Jasmine>

@harshlakhara
Copy link
Author

@alan-agius4 I have updated the scope to @schematics/angular

Please update the commit message and not the PR title, also one of the tests appear to be failing;

Failures:
1) Component Schematic standalone=false should error when class name contains invalid characters
  Message:
    Expected a promise to be rejected with Error: 'Class name "1Clazz" is invalid.' but it was rejected with Error: Selector "app-1-clazz" is invalid..
  Stack:
        at <Jasmine>
        at UserContext.<anonymous> (packages/schematics/angular/component/index_spec.ts:504:9)
        at <Jasmine>

working on it. Will update the PR with the changes.

@angular-robot angular-robot bot requested a review from alan-agius4 October 2, 2024 12:05
@harshlakhara harshlakhara force-pushed the harshlakhara/fix-component-directive-class-name-validation branch 3 times, most recently from a5eb495 to 454eb5e Compare October 2, 2024 12:23
@harshlakhara
Copy link
Author

@alan-agius4 I have updated the PR

@harshlakhara harshlakhara force-pushed the harshlakhara/fix-component-directive-class-name-validation branch from 454eb5e to 5afcaa6 Compare October 2, 2024 12:37
@alan-agius4 alan-agius4 removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews area: @angular/cli labels Oct 3, 2024
@harshlakhara
Copy link
Author

@alan-agius4 husky is throwing error with module not found and its not able to lint the file.

@alan-agius4
Copy link
Collaborator

Can you try to run yarn ng-dev format changed?

@harshlakhara harshlakhara force-pushed the harshlakhara/fix-component-directive-class-name-validation branch from 5afcaa6 to 1fd0ed4 Compare October 4, 2024 01:52
@angular-robot angular-robot bot added the area: build & ci Related the build and CI infrastructure of the project label Oct 4, 2024
@harshlakhara harshlakhara force-pushed the harshlakhara/fix-component-directive-class-name-validation branch from 1fd0ed4 to 2f9bef8 Compare October 4, 2024 01:54
@angular-robot angular-robot bot removed the area: build & ci Related the build and CI infrastructure of the project label Oct 4, 2024
@harshlakhara harshlakhara force-pushed the harshlakhara/fix-component-directive-class-name-validation branch from 2f9bef8 to a42660c Compare October 4, 2024 02:00
@harshlakhara
Copy link
Author

@alan-agius4 I have raised other PR #28566 for clean code as I messed git in this currenct PR. Sorry and Thanks.

@harshlakhara harshlakhara deleted the harshlakhara/fix-component-directive-class-name-validation branch October 4, 2024 02:08
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: @schematics/angular target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@angular/cli accepts component name starting with numerical character which is not supported as class name

2 participants