Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
260 changes: 15 additions & 245 deletions src/FSharpLint.Core/Application/Configuration.fs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/FSharpLint.Core/Application/Lint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ module Lint =
ReportLinterProgress = projectProgress }

let isIgnoredFile filePath =
config.ignoreFiles
config.IgnoreFiles
|> Option.map (fun ignoreFiles ->
let parsedIgnoreFiles = ignoreFiles |> Array.map IgnoreFiles.parseIgnorePath |> Array.toList
Configuration.IgnoreFiles.shouldFileBeIgnored parsedIgnoreFiles filePath)
Expand Down
12 changes: 2 additions & 10 deletions src/FSharpLint.Core/Framework/Rules.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,14 @@
open FSharp.Compiler.SyntaxTree
open FSharp.Compiler.Range
open FSharp.Compiler.SourceCodeServices
open FSharpLint.Framework.AbstractSyntaxArray
open FSharpLint.Framework.Ast
open FSharpLint.Framework.Suggestion

// Non-standard record field names for serialization
// fsharplint:disable RecordFieldNames
type GlobalRuleConfig =
{
numIndentationSpaces:int
}
{ NumIndentationSpaces:int }
with
static member Default =
{
GlobalRuleConfig.numIndentationSpaces = 4
}
// fsharplint:enable RecordFieldNames
{ GlobalRuleConfig.NumIndentationSpaces = 4 }

type AstNodeRuleParams =
{ AstNode:AstNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let check (config:Config) (args:AstNodeRuleParams) matchExprRange (clauses:SynMa
|> Option.bind (fun firstClause ->
let clauseIndentation = ExpressionUtilities.getLeadingSpaces firstClause.Range args.FileContent
if isLambda then
if clauseIndentation <> matchStartIndentation + args.GlobalConfig.numIndentationSpaces then
if clauseIndentation <> matchStartIndentation + args.GlobalConfig.NumIndentationSpaces then
{ Range = firstClause.Range
Message = Resources.GetString("RulesFormattingLambdaPatternMatchClauseIndentationError")
SuggestedFix = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let check (args:AstNodeRuleParams) _ (clauses:SynMatchClause list) _ =
guard
|> Option.map (fun expr -> expr.Range.EndLine)
|> Option.defaultValue pat.Range.EndLine
if expr.Range.StartLine <> matchPatternEndLine && exprIndentation <> clauseIndentation + args.GlobalConfig.numIndentationSpaces then
if expr.Range.StartLine <> matchPatternEndLine && exprIndentation <> clauseIndentation + args.GlobalConfig.NumIndentationSpaces then
{ Range = expr.Range
Message = Resources.GetString("RulesFormattingMatchExpressionIndentationError")
SuggestedFix = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let checkUnionDefinitionIndentation (args:AstNodeRuleParams) typeDefnRepr typeDe
| [_] -> Array.empty
| firstCase :: _ ->
let indentationLevelError =
if getUnionCaseStartColumn firstCase - 2 <> typeDefnStartColumn + args.GlobalConfig.numIndentationSpaces then
if getUnionCaseStartColumn firstCase - 2 <> typeDefnStartColumn + args.GlobalConfig.NumIndentationSpaces then
{ Range = firstCase.Range
Message = Resources.GetString("RulesFormattingUnionDefinitionIndentationError")
SuggestedFix = None
Expand Down
2 changes: 1 addition & 1 deletion src/FSharpLint.Core/Rules/Typography/Indentation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ let checkIndentation (expectedSpaces:int) (line:string) (lineNumber:int) (indent
None

let runner context args =
checkIndentation args.GlobalConfig.numIndentationSpaces args.Line args.LineNumber context
checkIndentation args.GlobalConfig.NumIndentationSpaces args.Line args.LineNumber context
|> Option.toArray

let rule =
Expand Down
56 changes: 56 additions & 0 deletions tests/FSharpLint.Console.Tests/TestApp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,59 @@ type TestConsoleApplication() =

Assert.AreEqual(0, returnCode)
Assert.AreEqual(Set.empty, errors)

/// Regression test for: https://github.com/fsprojects/FSharpLint/issues/466
/// Hints listed in the ignore section of the config were not being ignored.
[<Test>]
member __.``Ignoring a hint in the configuration should stop it from being output as warning.``() =
let input = """
let x = [1; 2; 3; 4] |> List.map (fun x -> x + 2) |> List.map (fun x -> x + 2)
"""

let (returnCode, errors) = main [| "lint"; input |]

// Check default config triggers the hint we're expecting to ignore later.
Assert.AreEqual(-1, returnCode)
Assert.AreEqual(Set.ofList ["`List.map f (List.map g x)` might be able to be refactored into `List.map (g >> f) x`."], errors)

let config = """
{
"hints": {
"add": [],
"ignore": [
"List.map f (List.map g x) ===> List.map (g >> f) x"
]
}
}
"""
use config = new TemporaryFile(config, "json")

let (returnCode, errors) = main [| "lint"; "--lint-config"; config.FileName; input |]

Assert.AreEqual(0, returnCode)
Assert.AreEqual(Set.empty, errors)

/// Regression test for bug discovered during: https://github.com/fsprojects/FSharpLint/issues/466
/// Adding a rule to the config was disabling other rules unless they're explicitly specified.
[<Test>]
member __.``Adding a rule to a custom config should not have side effects on other rules (from the default config).``() =
let config = """
{
exceptionNames: {
enabled: false
}
}
"""
use config = new TemporaryFile(config, "json")

// Should trigger warning for InterfaceNames rule.
let input = """
type Signature =
abstract member Encoded : string
abstract member PathName : string
"""

let (returnCode, errors) = main [| "lint"; "--lint-config"; config.FileName; input |]

Assert.AreEqual(-1, returnCode)
Assert.AreEqual(Set.ofList ["Consider changing `Signature` to be prefixed with `I`."], errors)