11

When I create Angular application, I am using CLI for generating components. After certain time of developing app I have style file for every component but major part of them are empty.

When I check sonar I have Code smells in empty style files:

  • Remove this empty stylesheet.
  • Add an empty new line at the end of this file.

Should I remove sonar rules or I must delete all empty style files in project and recreating them in next versions of project when I need them for component styling? What are best practices?

Gregor Albert
  • 819
  • 1
  • 11
  • 23

2 Answers2

5

For me, you can let the CSS / SCSS files empty. Just because after the build everything around styling will be minified and contained the "styles.js" file. So, even if it's a bit ugly to see all these empty files in dev mode, the compiler will solve your probelm by itself

this is a screen of your project after build :

enter image description here

Hadrien Delphin
  • 590
  • 1
  • 6
  • 19
  • 1
    this falls under major issue for sonar though https://rules.sonarsource.com/css/RSPEC-4667 – Abhishek Anand Oct 16 '20 at 11:18
  • @AbhishekAnand yes, but keep in mind, that the empty files are there pre build. During the build webpack will merge the styles in one or two file (js files BTW). So keep empty styles inside your Angular project is actually not an issue. – Hadrien Delphin Nov 03 '20 at 16:59
  • agreed. it's just weird is what I meant. this just shows meaningless major in sonar – Abhishek Anand Nov 05 '20 at 08:45
0

The main question is: empty scss files... What are best practices?

Empty files in a project is a bad practice. no one like to have useless files in their file browser.

I am against @AbhishekAnand answer "the compiler will solve your probelm by itself":

The compiler did not solve the problem for me, the empty files are uglier and I still can't tell the benefits of minifying an empty files.

My opinion is to remove the "styleUrls" from the component, delete the empty scss and create it when you need it.

It will feel good like you just loose weight!

Moh
  • 87
  • 2
  • 4