Development Tip

Visual Studio에서 명명 규칙 위반 메시지를 제거하는 방법은 무엇입니까?

yourdevel 2020. 10. 28. 21:11
반응형

Visual Studio에서 명명 규칙 위반 메시지를 제거하는 방법은 무엇입니까?


방금 Visual Studio 2017을 설치했습니다. 기존 웹 사이트를 열면 다음과 같은 모든 종류의 경고 메시지가 표시됩니다.

IDE1006 명명 규칙 위반 : 다음 단어는 대문자로 시작해야합니다. swe_calc

코드에서 다음과 같이 정의됩니다.

[System.Runtime.InteropServices.DllImport("swedll32.dll")]
public static extern Int32 swe_calc(double tjd, int ipl, Int32 iflag, IntPtr xx, IntPtr serr);

이것은 내 ASP.Net 컨트롤에서도 발생합니다. DropDownList의 예 :

IDE1006 이름 지정 규칙 위반 : 다음 단어는 대문자로 시작해야합니다. ddlMonth_SelectedIndexChanged

Visual Studio에서 이러한 유형의 경고를 제거하려면 어떻게해야합니까?


새로운 구성 가능한 기능입니다.

옵션 → 텍스트 편집기 → 사용자 언어 (C #를 사용함) → 코드 스타일 → 이름 지정

여기에서 스타일 관리로 이동하여 카멜 케이스를 추가합니다 (그 안에 있지만 선택 항목에 추가해야 함). "+"기호로 이동 한 다음 그에 따라 규칙을 추가합니다.

중요 : 변경 사항을 적용하려면 솔루션을 닫고 다시여십시오.

예를 들어, 나는 사적인 방법에만 camel Case를 사용합니다. 그래서 저는 Private Method를 선택하고 제가 만든 새로운 "camel Case"를 Style로 설정하고 Severity Suggestion으로 설정했습니다.

내장 된 기능도 모두 "제안"이므로 메시지를 끌 수도 있습니다.


이러한 메시지를 제거해야하는 경우 메시지를 억제 할 수도 있습니다.

여기에 이미지 설명 입력


일부 파일 또는 영역에서만 억제하려면 다음을 사용할 수 있습니다.

#pragma warning disable IDE1006

// the code with the warning

#pragma warning restore IDE1006

메서드의 이름을 바꾸고 속성이있는 EntryPoint속성에 이름을 추가 할 수 있습니다.

[System.Runtime.InteropServices.DllImport("swedll32.dll", EntryPoint = "swe_calc")]
public static extern Int32 SweCalc(double tjd, int ipl, Int32 iflag, IntPtr xx, IntPtr serr);

메서드에서 경고 메시지를 생략하거나 무효화하려면 System.Diagnostics.CodeAnalysis 네임 스페이스 에서 SuppressMessage사용할 수 있습니다 .

[SuppressMessage("Microsoft.Design", "IDE1006", Justification = "Rule violation aceppted due blah blah..")]

정당성의 속성은 선택 사항이지만, 그것의 가치는 코드를 수정하고 확인 상태인지 팀의 노하우를 수 있도록, 이유를 쓰는 순간을 지출.


.editorconfig이름 지정 규칙을 사용하여 설정 파일을 사용하여 일반 VS2017 및 VS2019를 사용하여 수행 할 수 있습니다 . https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference

파일은 손으로 만들 수 있습니다. 또는 VS2019에서 Visual Studio를 사용하여 기본 설정에서 만들 수 있습니다 (예 : https://stackoverflow.com/a/41131563/131701 에서와 같이 환경 설정을 구성한 후 ). 설정 버튼에서 편집기 구성 파일 생성.

설정 버튼에서 편집기 구성 파일 생성

For example, the following sets of rules will enable camelCase for all non public methods, and keep the other default naming rules that comes with VS.

#### Naming styles ####

# Naming rules

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.private_method_should_be_camelcasestyle.severity = suggestion
dotnet_naming_rule.private_method_should_be_camelcasestyle.symbols = private_method
dotnet_naming_rule.private_method_should_be_camelcasestyle.style = camelcasestyle

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal
dotnet_naming_symbols.interface.required_modifiers = 

dotnet_naming_symbols.private_method.applicable_kinds = method
dotnet_naming_symbols.private_method.applicable_accessibilities = private, protected, internal, protected_internal
dotnet_naming_symbols.private_method.required_modifiers = 

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal
dotnet_naming_symbols.types.required_modifiers = 

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal
dotnet_naming_symbols.non_field_members.required_modifiers = 

# Naming styles

dotnet_naming_style.pascal_case.required_prefix = 
dotnet_naming_style.pascal_case.required_suffix = 
dotnet_naming_style.pascal_case.word_separator = 
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix = 
dotnet_naming_style.begins_with_i.word_separator = 
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.camelcasestyle.required_prefix = 
dotnet_naming_style.camelcasestyle.required_suffix = 
dotnet_naming_style.camelcasestyle.word_separator = 
dotnet_naming_style.camelcasestyle.capitalization = camel_case

If you hover over the naming rule violation, you can use Alt + Enter to bring up the naming styles for that language. You can also use Tools -> Options -> Text Editor -> {language} -> Code Style -> Naming.

For camelCase rules on Methods, you can add a new rule and set that to Camel Case. When you close the code file and open it up again, you shouldn't see that warning anymore. Not sure why this isn't a default option, but it wasn't in my case (using Visual Code 15.8). I had to edit styles to match our company standards.

Sample C# Naming Styles Settings

참고 URL : https://stackoverflow.com/questions/40856186/how-to-get-rid-of-naming-rule-violation-messages-in-visual-studio

반응형