Resharper:如何抑制 CSS 黑客攻击导致的检查错误?
有问题的代码是这样的:
/*fix ie transform offset*/
.adAffiliate.adDeclarationPosition-Right .adAffiliate-header
{
*left: -20px !important; /* IE 7 (IE6 also uses this, so put it first) */
_left: -20px !important; /* IE 6 */
left: -20px\0/ !important; /* IE 8-9 */
}
如您所见,前两行被识别为 CSS hack。它们不会出现在解决方案错误列表中。我只想删除解决方案错误列表中出现的第三行。 不幸的是,“忽略错误”在 VS 重新启动时不起作用。有没有办法抑制这个特定的错误?也许是一个特殊的“忽略评论”?
这是我在数千个 LOC 中唯一的 CSS hack。我只是这次没有找到出路。我对这个黑客的存在感到满意。
The code in question is this:
/*fix ie transform offset*/
.adAffiliate.adDeclarationPosition-Right .adAffiliate-header
{
*left: -20px !important; /* IE 7 (IE6 also uses this, so put it first) */
_left: -20px !important; /* IE 6 */
left: -20px\0/ !important; /* IE 8-9 */
}
As you can see, the first two lines get recognized as CSS hacks. They do not appear in the solution error list. I just want to get rid of the 3rd line appearing in the solution error list. Unfortunately, "ignore error" does not work across VS restarts. Is there a way to suppress this particular error? Maybe a special "ignore comment"?
This is the only CSS hack I have in 1000s of LOC. I just did not find a way out this time. And I am ok with this hack being there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需在错误突出显示时按Alt+Enter,选择检查选项...并将严重性设置为警告,即可更改此类错误的严重性或更低。
这将迫使问题从解决方案中的错误工具窗口中消失,显然,该窗口仅显示错误级别的问题。请注意,检查严重性更改在 VS 重新启动后仍然存在。
当然,这个解决方案意味着,每当您的代码在其他地方碰巧遇到类似问题时,您将无法通过解决方案中的错误观察到它:您要么必须密切关注ReSharper 问题在代码编辑器中突出显示(无论如何,这是一个有用的习惯)或使用 ReSharper > 检查您的代码检查> 范围中的代码问题
Just change severity for this type of error by pressing Alt+Enter at the error highlighting, selecting Inspection options... and setting severity to Warning or lower.
This would force the issue to disappear from the Errors in Solution tool window which, obviously, shows only error-level issues. Mind you, inspection severity changes persist across VS restarts.
Of course, this solution implies that whenever your code happens to have a similar issue somewhere else, you won't be able to observe it through Errors in Solution: you'll either have to keep your eye on ReSharper issue highlighting in the code editor (a useful habit anyway) or inspect your code with ReSharper > Inspect > Code Issues in scope
你称之为CSS hacks,我称之为无效CSS(验证器也这样做)。我建议使用 条件注释 包含的不同 css 文件。这是更多的工作,但它更干净。
You call it CSS hacks, I call it invalid CSS (and the validator does it too). I recommend to use different css files included by i.e. conditional comments. This is more work, but it is much cleaner.