简体   繁体   English

我如何在编辑器中检查class属性的类是否在库中?

[英]How do I check in the editor if the class of class attribute is in the library?

What I want to achieve 我想实现的目标

I want to detect when the class name of the general CSS library and the class name declaration of my CSS file are duplicated (On the editor of PHPStorm, Atom, VSCode, etc). 我想检测通用CSS库的类名和CSS文件的类名声明何时重复(在PHPStorm,Atom,VSCode等编辑器上)。

Is there a way to detect in the HTML file if the class name is duplicated? 是否可以在HTML文件中检测类名是否重复?


What I examined (but they are useless) 我检查过的东西(但是它们没用)

So I searched for CSS Lint and found CSS LINT and stylelint . 所以我搜索了CSS Lint并找到了CSS LINTstylelint

However, it seems that CSS LINT does not have a function to detect duplicate class names, and the following CSS did not issue any errors or warnings. 但是,似乎CSS LINT没有检测重复类名称的功能,并且以下CSS不会发出任何错误或警告。

.duplicate_class {
  background: #ffa;
}

.duplicate_class {
  font-size: 5px; /* I want errors and warnings */
}

stylelint's no-duplicate-selectors check selectors instead of class names, thus allowing duplicate class names: stylelint的无重复选择器检查选择器而不是类名称,从而允许重复的类名称:

.class {
  background: #ffa;
}

body .class {
  font-size: 5px;
}

Of course, htmllint didn't have the ability to detect duplicate class names. 当然,htmllint不能检测重复的类名。

I have never come across such a plug, a tool. 我从来没有遇到过这样的插件,工具。 But it is possible to combine such classes. 但是可以组合这样的类。

Input 输入项

.module {
  color: green;
}
.another-module {
  color: blue;
}
.module {
  background: red;
}
.another-module {
  background: yellow;
}

Output 输出量

.module {
  color: green;
  background: red;
}
.another-module {
  color: blue;
  background: yellow;
}

Library is postcss and plugin postcss-combine-duplicated-selectors . 库是postcss和插件postcss-combine-duplicated-selectors Can be used from the command line. 可以从命令行使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM