Skip to content

Generated directive selector name should be camelcase #1216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Blasz opened this issue Jun 27, 2016 · 5 comments
Closed

Generated directive selector name should be camelcase #1216

Blasz opened this issue Jun 27, 2016 · 5 comments

Comments

@Blasz
Copy link

Blasz commented Jun 27, 2016

Version
$ ng --version
(node:20286) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
angular-cli: 1.0.0-beta.6
node: 6.2.1
os: linux x64
Repro steps

The following generate command produces a kebab case selector name instead of camelCase.

$ ng g directive shared/directives/wrap-if
(node:20210) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
installing directive
  create src/app/shared/directives/wrap-if.directive.spec.ts
  create src/app/shared/directives/wrap-if.directive.ts

src/app/shared/directives/wrap-if.directive.ts

import { Directive } from '@angular/core';

@Directive({
  selector: '[wrap-if]'
})
export class WrapIf {

  constructor() {}

}

As per the styleguide,

Do Use lower camel case for naming the selectors of our directives.

I've passed ng generate the name in kebab case because the README states so and follows the convention of passing the file name where file names should use dashes to separate words in the descriptive name.

I've read #424 and acknowledge that passing the name as camelCase to ng generate produces the correct selector but it is unintuitive and doesn't follow the README. I don't think we should make an exception to the convention of passing kebab case file names to ng generate.

Instead of not modifying the selector name at all for directives, I think they should be modified to be camelCase as per the styleguide.

@choeller
Copy link

As an addition according to the Style-Guide, the Selector for Directives should also take the prefix of the app into account. So I would assume

ng g directive lower-case

to create a Direktive with the selector

[appLowerCase]

@filipesilva
Copy link
Contributor

@Brocco can you weigh in?

@Brocco
Copy link
Contributor

Brocco commented Sep 24, 2016

The style guide does dictate camelCase for directive selectors and prefixing them with the application prefix. I will put together a PR for this.

Reference: https://angular.io/docs/ts/latest/guide/style-guide.html#!#02-08

Brocco added a commit to Brocco/angular-cli that referenced this issue Sep 24, 2016
JJayet pushed a commit to JJayet/angular-cli that referenced this issue Oct 2, 2016
deebloo pushed a commit to deebloo/angular-cli that referenced this issue Oct 3, 2016
@nukec
Copy link

nukec commented Jun 12, 2019

what if you prefix is kebab case? app-something, then you are doomed. why is component kebab case and directive camel case in style guide? can't we just use kebab case for everything consistently?

@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 Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants