33
44namespace StyleCop . Analyzers
55{
6+ using System ;
67 using System . Collections . Immutable ;
78 using System . IO ;
89 using System . Threading ;
@@ -18,6 +19,7 @@ namespace StyleCop.Analyzers
1819 internal static class SettingsHelper
1920 {
2021 internal const string SettingsFileName = "stylecop.json" ;
22+ internal const string AltSettingsFileName = ".stylecop.json" ;
2123
2224 private static readonly SourceTextValueProvider < StyleCopSettings > SettingsValueProvider =
2325 new SourceTextValueProvider < StyleCopSettings > (
@@ -73,14 +75,15 @@ internal static StyleCopSettings GetStyleCopSettings(this AnalyzerOptions option
7375 /// <returns><c>true</c> if <paramref name="path"/> points to a StyleCop settings file; otherwise, <c>false</c>.</returns>
7476 internal static bool IsStyleCopSettingsFile ( string path )
7577 {
76- var fileName = Path . GetFileName ( path ) . ToLowerInvariant ( ) ;
77-
78- if ( fileName . StartsWith ( "." ) )
78+ if ( path == null )
7979 {
80- fileName = fileName . Substring ( 1 ) ;
80+ throw new ArgumentNullException ( nameof ( path ) ) ;
8181 }
8282
83- return fileName == SettingsFileName ;
83+ var fileName = Path . GetFileName ( path ) ;
84+
85+ return string . Equals ( fileName , SettingsFileName , StringComparison . OrdinalIgnoreCase )
86+ || string . Equals ( fileName , AltSettingsFileName , StringComparison . OrdinalIgnoreCase ) ;
8487 }
8588
8689 internal static StyleCopSettings GetStyleCopSettings ( this AnalysisContext context , AnalyzerOptions options , CancellationToken cancellationToken )
@@ -90,8 +93,8 @@ internal static StyleCopSettings GetStyleCopSettings(this AnalysisContext contex
9093
9194 internal static StyleCopSettings GetStyleCopSettings ( this AnalysisContext context , AnalyzerOptions options , DeserializationFailureBehavior failureBehavior , CancellationToken cancellationToken )
9295 {
93- string settingsFileName ;
94- SourceText text = TryGetStyleCopSettingsText ( options , cancellationToken , out settingsFileName ) ;
96+ string settingsFilePath ;
97+ SourceText text = TryGetStyleCopSettingsText ( options , cancellationToken , out settingsFilePath ) ;
9598 if ( text == null )
9699 {
97100 return new StyleCopSettings ( ) ;
@@ -108,7 +111,7 @@ internal static StyleCopSettings GetStyleCopSettings(this AnalysisContext contex
108111 return settings ;
109112 }
110113
111- return GetStyleCopSettings ( settingsFileName , text , failureBehavior ) ;
114+ return GetStyleCopSettings ( settingsFilePath , text , failureBehavior ) ;
112115 }
113116
114117 internal static StyleCopSettings GetStyleCopSettings ( this CompilationStartAnalysisContext context , AnalyzerOptions options , CancellationToken cancellationToken )
@@ -120,8 +123,8 @@ internal static StyleCopSettings GetStyleCopSettings(this CompilationStartAnalys
120123 internal static StyleCopSettings GetStyleCopSettings ( this CompilationStartAnalysisContext context , AnalyzerOptions options , DeserializationFailureBehavior failureBehavior , CancellationToken cancellationToken )
121124#pragma warning restore RS1012 // Start action has no registered actions.
122125 {
123- string settingsFileName ;
124- SourceText text = TryGetStyleCopSettingsText ( options , cancellationToken , out settingsFileName ) ;
126+ string settingsFilePath ;
127+ SourceText text = TryGetStyleCopSettingsText ( options , cancellationToken , out settingsFilePath ) ;
125128 if ( text == null )
126129 {
127130 return new StyleCopSettings ( ) ;
@@ -138,7 +141,7 @@ internal static StyleCopSettings GetStyleCopSettings(this CompilationStartAnalys
138141 return settings ;
139142 }
140143
141- return GetStyleCopSettings ( settingsFileName , text , failureBehavior ) ;
144+ return GetStyleCopSettings ( settingsFilePath , text , failureBehavior ) ;
142145 }
143146
144147 private static StyleCopSettings GetStyleCopSettings ( string path , SourceText text , DeserializationFailureBehavior failureBehavior )
@@ -178,19 +181,19 @@ private static StyleCopSettings GetStyleCopSettings(string path, SourceText text
178181 return new StyleCopSettings ( ) ;
179182 }
180183
181- private static SourceText TryGetStyleCopSettingsText ( this AnalyzerOptions options , CancellationToken cancellationToken , out string settingsFileName )
184+ private static SourceText TryGetStyleCopSettingsText ( this AnalyzerOptions options , CancellationToken cancellationToken , out string settingsFilePath )
182185 {
183186 foreach ( var additionalFile in options . AdditionalFiles )
184187 {
185188 if ( IsStyleCopSettingsFile ( additionalFile . Path ) )
186189 {
187- settingsFileName = additionalFile . Path ;
190+ settingsFilePath = additionalFile . Path ;
188191
189192 return additionalFile . GetText ( cancellationToken ) ;
190193 }
191194 }
192195
193- settingsFileName = null ;
196+ settingsFilePath = null ;
194197
195198 return null ;
196199 }
0 commit comments