Research prettier/CSS #710

Closed
opened 2026-05-04 12:21:44 +00:00 by a24julot · 3 comments
Collaborator

Research if prettier can be configured to have other settings for CSS files. Indentation should be 2 for CSS and when naming a rule set example-xxx. When referring to the rule set in the .js file, spaces are automatically made (styles.example - xxx) which results in an error. Is it better to use camelCase for naming or is prettier configurable to follow our standards?

Research if prettier can be configured to have other settings for CSS files. Indentation should be 2 for CSS and when naming a rule set example-xxx. When referring to the rule set in the .js file, spaces are automatically made (styles.example - xxx) which results in an error. Is it better to use camelCase for naming or is prettier configurable to follow our standards?
Collaborator

Research:

Aimed towards if prettier can handle files differently and how we should go forward with the naming conventions for our css.

Naming issue:

From my research there is no clear prettier configuration that can solve the naming issue as the problem is not related to how prettier formats the css rather it relates to how Javascript parses property names when using css.

As we are using "kebab-case" the Javascript interprets this as a subtraction which changes the naming from:

.example-xxx

to:

.example - xxx

There is technically one thing that can be implemented to solve the naming issue and that's by using bracket-notation. Basically when importing the css from a module you would write:

styles['example-xxx'];

Instead of:

styles.example-xxx;

However this can lead to issues such as its easier to forget, less readable and can lead to developer errors. Therefore the easier and better solution is probably to switch our naming conventions and rules from kebab-case to camelCase.

Indentation issue:

Prettier can be used to handle the css separately from other files by using the configuration option override.

using something along these lines.

{
  "tabWidth": 4,
  "overrides": [
    {
      "files": ["*.css"],
      "options": {
        "tabWidth": 2
      }
    }
  ]
}

https://prettier.io/docs/options

https://prettier.io/docs/configuration

https://medium.com/@bhuvaneshcj/snake-case-vs-camel-case-vs-pascal-case-vs-kebab-case-understanding-code-naming-conventions-6f500676e3fd

### Research: Aimed towards if prettier can handle files differently and how we should go forward with the naming conventions for our css. ### Naming issue: From my research there is no clear prettier configuration that can solve the naming issue as the problem is not related to how prettier formats the css rather it relates to how Javascript parses property names when using css. As we are using "kebab-case" the Javascript interprets this as a subtraction which changes the naming from: `.example-xxx` to: `.example - xxx` There is technically one thing that can be implemented to solve the naming issue and that's by using bracket-notation. Basically when importing the css from a module you would write: `styles['example-xxx'];` Instead of: `styles.example-xxx; ` However this can lead to issues such as its easier to forget, less readable and can lead to developer errors. Therefore the easier and better solution is probably to switch our naming conventions and rules from kebab-case to camelCase. ### Indentation issue: Prettier can be used to handle the css separately from other files by using the configuration option **override**. using something along these lines. ``` { "tabWidth": 4, "overrides": [ { "files": ["*.css"], "options": { "tabWidth": 2 } } ] } ``` ### Links: https://prettier.io/docs/options https://prettier.io/docs/configuration https://medium.com/@bhuvaneshcj/snake-case-vs-camel-case-vs-pascal-case-vs-kebab-case-understanding-code-naming-conventions-6f500676e3fd
Author
Collaborator

The solution with brackets works as intended, will ask the customer if kebab-case och camelCase is the best way to go.

The solution with brackets works as intended, will ask the customer if kebab-case och camelCase is the best way to go.
Author
Collaborator

We made the decision that kebab-case with brackets will be used.

We made the decision that kebab-case with brackets will be used.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Andras/BoundlessFlowCampus2K#710
No description provided.