Skip to content

Commit a94526d

Browse files
author
Matt
authored
Merge pull request #242 from fsprojects/issue-240
Issue 240
2 parents 5e57551 + 1ce8651 commit a94526d

File tree

5 files changed

+51
-12
lines changed

5 files changed

+51
-12
lines changed

RELEASE_NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
##### 0.8.1 - October 10 2017
2+
3+
* Fixed https://github.com/fsprojects/FSharpLint/issues/240
4+
15
##### 0.8.0 - September 05 2017
26

37
* Updated `FSharp.Compiler.Service`

src/FSharpLint.Core/Framework/ParseFile.fs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ module ParseFile =
9393
parse configuration file source (checker, projectOptions)
9494

9595
/// Parses source code using `FSharp.Compiler.Service`.
96-
let parseSource source configuration (checker:FSharpChecker) =
97-
let file = "test.fsx"
98-
99-
let options = getProjectOptionsFromScript checker file source
96+
let parseSourceFile fileName source configuration (checker:FSharpChecker) =
97+
let options = getProjectOptionsFromScript checker fileName source
10098

101-
parse configuration file source (checker, options)
99+
parse configuration fileName source (checker, options)
100+
101+
let parseSource source configuration (checker:FSharpChecker) =
102+
parseSourceFile "test.fsx" source configuration checker

src/FSharpLint.Core/Rules/NameConventions.fs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,15 @@ module NameConventions =
410410
| SynSimplePat.Id(ident, _, _, _, _, _) -> Some(ident)
411411
| SynSimplePat.Typed(p, _, _) -> identFromSimplePat p
412412
| SynSimplePat.Attrib(_) -> None
413+
414+
/// Is module name implicitly created from file name?
415+
let private isImplicitModule (SynModuleOrNamespace.SynModuleOrNamespace(longIdent, _, isModule, _, _, _, _, range)) =
416+
let zeroLengthRange (r:range) =
417+
(r.EndColumn - r.StartColumn) = 0 && r.StartLine = r.EndLine
418+
419+
// Check the identifiers in the module name have no length.
420+
// Not ideal but there's no attribute in the AST indicating the module is implicit from the file name.
421+
isModule && longIdent |> List.forall (fun x -> zeroLengthRange x.idRange)
413422

414423
let analyser (args: AnalyserArgs) : unit =
415424
let syntaxArray, skipArray = args.SyntaxArray, args.SkipArray
@@ -441,12 +450,13 @@ module NameConventions =
441450
let checkRule = checkNamingRule i
442451

443452
match syntaxArray.[i].Actual with
444-
| AstNode.ModuleOrNamespace(SynModuleOrNamespace.SynModuleOrNamespace(identifier, _, isModule, _, _, _, _, _)) ->
445-
let checkIdent =
446-
if isModule then checkRule rules.ModuleNames
447-
else checkRule rules.NamespaceNames
453+
| AstNode.ModuleOrNamespace(SynModuleOrNamespace.SynModuleOrNamespace(identifier, _, isModule, _, _, _, _, _) as synModule) ->
454+
if not <| isImplicitModule synModule then
455+
let checkIdent =
456+
if isModule then checkRule rules.ModuleNames
457+
else checkRule rules.NamespaceNames
448458

449-
identifier |> List.collect checkIdent |> List.iter args.Info.Suggest
459+
identifier |> List.collect checkIdent |> List.iter args.Info.Suggest
450460
| AstNode.UnionCase(SynUnionCase.UnionCase(_, identifier, _, _, _, _)) ->
451461
checkRule rules.UnionCasesNames identifier |> List.iter args.Info.Suggest
452462
| AstNode.Field(SynField.Field(_, _, identifier, _, _, _, _, _)) ->

tests/FSharpLint.Core.Tests/Rules/TestNameConventionRules.fs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
open NUnit.Framework
44
open FSharpLint.Rules.NameConventions
5+
open FSharpLint.Framework
56
open FSharpLint.Framework.Configuration
67

78
let config =
@@ -63,6 +64,24 @@ type TestNameConventionRules() =
6364
member this.``Performance of naming analyser``() =
6465
Assert.Less(this.TimeAnalyser(100, defaultConfiguration), 20)
6566

67+
/// Regression test for: https://github.com/fsprojects/FSharpLint/issues/240
68+
[<Test>]
69+
member this.``Linter must not complain about naming of fsx file``() =
70+
this.Parse(input = """
71+
type MyClass2() as this =
72+
member this.PrintMessage() = ()""", fileName = "3i-3.fsx")
73+
74+
this.AssertNoWarnings()
75+
76+
/// Regression test for: https://github.com/fsprojects/FSharpLint/issues/240
77+
[<Test>]
78+
member this.``Linter must not complain about naming of fsx file with long name``() =
79+
this.Parse(input = """
80+
type MyClass2() as this =
81+
member this.PrintMessage() = ()""", fileName = "foo.3i-3.fsx")
82+
83+
this.AssertNoWarnings()
84+
6685
[<Test>]
6786
member __.IsPascalCase() =
6887
Assert.IsTrue(isPascalCase "DogInBin")

tests/FSharpLint.Core.Tests/Rules/TestRuleBase.fs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type TestRuleBase(analyser, ?analysers) =
7676

7777
result
7878

79-
member __.Parse(input:string, ?overrideAnalysers, ?checkInput, ?fsharpVersion): unit =
79+
member __.Parse(input:string, ?overrideAnalysers, ?checkInput, ?fsharpVersion, ?fileName): unit =
8080
let config =
8181
match overrideAnalysers with
8282
| Some(overrideAnalysers) ->
@@ -91,8 +91,13 @@ type TestRuleBase(analyser, ?analysers) =
9191
Suggest = postSuggestion
9292
FSharpVersion = version
9393
Text = input }
94+
95+
let parseResults =
96+
match fileName with
97+
| Some(fileName) -> parseSourceFile fileName input config (FSharpChecker.Create())
98+
| None -> parseSource input config (FSharpChecker.Create())
9499

95-
match parseSource input config (FSharpChecker.Create()) with
100+
match parseResults with
96101
| Success(parseInfo) ->
97102
let (syntaxArray, skipArray) = AbstractSyntaxArray.astToArray parseInfo.Ast
98103
analyser

0 commit comments

Comments
 (0)