diff --git a/docs/content/how-tos/rule-configuration.md b/docs/content/how-tos/rule-configuration.md index b0af74e66..80e55a677 100644 --- a/docs/content/how-tos/rule-configuration.md +++ b/docs/content/how-tos/rule-configuration.md @@ -115,7 +115,7 @@ The following rules can be specified for linting. - [FailwithBadUsage (FL0072)](rules/FL0072.html) - [FavourReRaise (FL0073)](rules/FL0073.html) - [FavourConsistentThis (FL0074)](rules/FL0074.html) -- [AvoidTooShortNames (FL0075)](rules/FL0075.html) +- [AvoidTooShortNaming (FL0075)](rules/FL0075.html) - [FavourStaticEmptyFields (FL0076)](rules/FL0076.html) - [AvoidSinglePipeOperator (FL0077)](rules/FL0077.html) - [AsyncExceptionWithoutReturn (FL0078)](rules/FL0078.html) diff --git a/docs/content/how-tos/rules/FL0075.md b/docs/content/how-tos/rules/FL0075.md index ce4d35d05..6890e6545 100644 --- a/docs/content/how-tos/rules/FL0075.md +++ b/docs/content/how-tos/rules/FL0075.md @@ -4,9 +4,9 @@ category: how-to hide_menu: true --- -# AvoidTooShortNames (FL0075) +# AvoidTooShortNaming (FL0075) -*Introduced in `0.21.1`* +*Introduced in `0.21.1`* (NOTE: in versions older than `1.0`, the rule was named `AvoidTooShortNames`.) ## Cause @@ -23,7 +23,7 @@ Use longer names for the flagged occurrences. ## Rule Settings { - "avoidTooShortNames": { + "avoidTooShortNaming": { "enabled": false } } diff --git a/src/FSharpLint.Core/Application/Configuration.fs b/src/FSharpLint.Core/Application/Configuration.fs index 86d784e9e..90b633d7c 100644 --- a/src/FSharpLint.Core/Application/Configuration.fs +++ b/src/FSharpLint.Core/Application/Configuration.fs @@ -132,8 +132,6 @@ module IgnoreFiles = when isCurrentlyIgnored && pathMatchesGlob glob segments isDirectory -> false | _ -> isCurrentlyIgnored) false ignorePaths -// Non-standard record field naming for config serialization. -// fsharplint:disable RecordFieldNames type RuleConfig<'Config> = { Enabled:bool Config:'Config option @@ -156,307 +154,21 @@ let constructTypePrefixingRuleWithConfig rule (ruleConfig: RuleConfig] -let private ObsoleteMsg = "Please rather provide these settings at root level instead of grouped. This type/member will be removed in the near future." -[] -let private ObsoleteWarnTreatAsError = false - -// to be able to use our own types that we mark as Obsolete -#nowarn "44" - -[] -type TupleFormattingConfig = - { tupleCommaSpacing:EnabledConfig option - tupleIndentation:EnabledConfig option - tupleParentheses:EnabledConfig option } -with - member this.Flatten() = - Array.choose id - [| - Option.bind (constructRuleIfEnabled TupleCommaSpacing.rule) this.tupleCommaSpacing - Option.bind (constructRuleIfEnabled TupleIndentation.rule) this.tupleIndentation - Option.bind (constructRuleIfEnabled TupleParentheses.rule) this.tupleParentheses - |] - -[] -type PatternMatchFormattingConfig = - { patternMatchClausesOnNewLine:EnabledConfig option - patternMatchOrClausesOnNewLine:EnabledConfig option - patternMatchClauseIndentation:RuleConfig option - patternMatchExpressionIndentation:EnabledConfig option } -with - member this.Flatten() = - Array.choose id - [| - Option.bind (constructRuleIfEnabled PatternMatchClausesOnNewLine.rule) this.patternMatchClausesOnNewLine - Option.bind (constructRuleIfEnabled PatternMatchOrClausesOnNewLine.rule) this.patternMatchOrClausesOnNewLine - Option.bind (constructRuleWithConfig PatternMatchClauseIndentation.rule) this.patternMatchClauseIndentation - Option.bind (constructRuleIfEnabled PatternMatchExpressionIndentation.rule) this.patternMatchExpressionIndentation - |] - -[] -type FormattingConfig = - { typedItemSpacing:RuleConfig option - typePrefixing:RuleConfig option - unionDefinitionIndentation:EnabledConfig option - moduleDeclSpacing:EnabledConfig option - classMemberSpacing:EnabledConfig option - tupleFormatting:TupleFormattingConfig option - patternMatchFormatting:PatternMatchFormattingConfig option } -with - member this.Flatten() = - Array.concat - [| - this.typedItemSpacing |> Option.bind (constructRuleWithConfig TypedItemSpacing.rule) |> Option.toArray - this.typePrefixing |> Option.bind (constructTypePrefixingRuleWithConfig TypePrefixing.rule) |> Option.toArray - this.unionDefinitionIndentation |> Option.bind (constructRuleIfEnabled UnionDefinitionIndentation.rule) |> Option.toArray - this.moduleDeclSpacing |> Option.bind (constructRuleIfEnabled ModuleDeclSpacing.rule) |> Option.toArray - this.classMemberSpacing |> Option.bind (constructRuleIfEnabled ClassMemberSpacing.rule) |> Option.toArray - this.tupleFormatting |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat - this.patternMatchFormatting |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat - |] - -[] -type RaiseWithTooManyArgsConfig = - { failwithBadUsage:EnabledConfig option - raiseWithSingleArgument:EnabledConfig option - nullArgWithSingleArgument:EnabledConfig option - invalidOpWithSingleArgument:EnabledConfig option - invalidArgWithTwoArguments:EnabledConfig option - failwithfWithArgumentsMatchingFormatString:EnabledConfig option } -with - member this.Flatten() = - Array.concat - [| - this.failwithBadUsage |> Option.bind (constructRuleIfEnabled FailwithBadUsage.rule) |> Option.toArray - this.raiseWithSingleArgument |> Option.bind (constructRuleIfEnabled RaiseWithSingleArgument.rule) |> Option.toArray - this.nullArgWithSingleArgument |> Option.bind (constructRuleIfEnabled NullArgWithSingleArgument.rule) |> Option.toArray - this.invalidOpWithSingleArgument |> Option.bind (constructRuleIfEnabled InvalidOpWithSingleArgument.rule) |> Option.toArray - this.invalidArgWithTwoArguments |> Option.bind (constructRuleIfEnabled InvalidArgWithTwoArguments.rule) |> Option.toArray - this.failwithfWithArgumentsMatchingFormatString |> Option.bind (constructRuleIfEnabled FailwithfWithArgumentsMatchingFormatString.rule) |> Option.toArray - |] - -[] -type SourceLengthConfig = - { maxLinesInLambdaFunction:RuleConfig option - maxLinesInMatchLambdaFunction:RuleConfig option - maxLinesInValue:RuleConfig option - maxLinesInFunction:RuleConfig option - maxLinesInMember:RuleConfig option - maxLinesInConstructor:RuleConfig option - maxLinesInProperty:RuleConfig option - maxLinesInModule:RuleConfig option - maxLinesInRecord:RuleConfig option - maxLinesInEnum:RuleConfig option - maxLinesInUnion:RuleConfig option - maxLinesInClass:RuleConfig option } -with - member this.Flatten() = - Array.concat - [| - this.maxLinesInLambdaFunction |> Option.bind (constructRuleWithConfig MaxLinesInLambdaFunction.rule) |> Option.toArray - this.maxLinesInMatchLambdaFunction |> Option.bind (constructRuleWithConfig MaxLinesInMatchLambdaFunction.rule) |> Option.toArray - this.maxLinesInValue |> Option.bind (constructRuleWithConfig MaxLinesInValue.rule) |> Option.toArray - this.maxLinesInFunction |> Option.bind (constructRuleWithConfig MaxLinesInFunction.rule) |> Option.toArray - this.maxLinesInMember |> Option.bind (constructRuleWithConfig MaxLinesInMember.rule) |> Option.toArray - this.maxLinesInConstructor |> Option.bind (constructRuleWithConfig MaxLinesInConstructor.rule) |> Option.toArray - this.maxLinesInProperty |> Option.bind (constructRuleWithConfig MaxLinesInProperty.rule) |> Option.toArray - this.maxLinesInModule |> Option.bind (constructRuleWithConfig MaxLinesInModule.rule) |> Option.toArray - this.maxLinesInRecord |> Option.bind (constructRuleWithConfig MaxLinesInRecord.rule) |> Option.toArray - this.maxLinesInEnum |> Option.bind (constructRuleWithConfig MaxLinesInEnum.rule) |> Option.toArray - this.maxLinesInUnion |> Option.bind (constructRuleWithConfig MaxLinesInUnion.rule) |> Option.toArray - this.maxLinesInClass |> Option.bind (constructRuleWithConfig MaxLinesInClass.rule) |> Option.toArray - |] - -[] -type NamesConfig = - { interfaceNames:RuleConfig option - genericTypesNames:RuleConfig option - exceptionNames:RuleConfig option - typeNames:RuleConfig option - recordFieldNames:RuleConfig option - enumCasesNames:RuleConfig option - unionCasesNames:RuleConfig option - moduleNames:RuleConfig option - literalNames:RuleConfig option - namespaceNames:RuleConfig option - memberNames:RuleConfig option - parameterNames:RuleConfig option - measureTypeNames:RuleConfig option - activePatternNames:RuleConfig option - publicValuesNames:RuleConfig option - nonPublicValuesNames:RuleConfig option - privateValuesNames:RuleConfig option - internalValuesNames:RuleConfig option } -with - member this.Flatten() = - Array.concat - [| - this.interfaceNames |> Option.bind (constructRuleWithConfig InterfaceNames.rule) |> Option.toArray - this.genericTypesNames |> Option.bind (constructRuleWithConfig GenericTypesNames.rule) |> Option.toArray - this.exceptionNames |> Option.bind (constructRuleWithConfig ExceptionNames.rule) |> Option.toArray - this.typeNames |> Option.bind (constructRuleWithConfig TypeNames.rule) |> Option.toArray - this.recordFieldNames |> Option.bind (constructRuleWithConfig RecordFieldNames.rule) |> Option.toArray - this.enumCasesNames |> Option.bind (constructRuleWithConfig EnumCasesNames.rule) |> Option.toArray - this.unionCasesNames |> Option.bind (constructRuleWithConfig UnionCasesNames.rule) |> Option.toArray - this.moduleNames |> Option.bind (constructRuleWithConfig ModuleNames.rule) |> Option.toArray - this.literalNames |> Option.bind (constructRuleWithConfig LiteralNames.rule) |> Option.toArray - this.namespaceNames |> Option.bind (constructRuleWithConfig NamespaceNames.rule) |> Option.toArray - this.memberNames |> Option.bind (constructRuleWithConfig MemberNames.rule) |> Option.toArray - this.parameterNames |> Option.bind (constructRuleWithConfig ParameterNames.rule) |> Option.toArray - this.measureTypeNames |> Option.bind (constructRuleWithConfig MeasureTypeNames.rule) |> Option.toArray - this.activePatternNames |> Option.bind (constructRuleWithConfig ActivePatternNames.rule) |> Option.toArray - this.publicValuesNames |> Option.bind (constructRuleWithConfig PublicValuesNames.rule) |> Option.toArray - this.nonPublicValuesNames |> Option.bind (constructRuleWithConfig PrivateValuesNames.rule) |> Option.toArray - this.nonPublicValuesNames |> Option.bind (constructRuleWithConfig InternalValuesNames.rule) |> Option.toArray - this.privateValuesNames |> Option.bind (constructRuleWithConfig PrivateValuesNames.rule) |> Option.toArray - this.internalValuesNames|> Option.bind (constructRuleWithConfig InternalValuesNames.rule) |> Option.toArray - |] - -[] -type NumberOfItemsConfig = - { maxNumberOfItemsInTuple:RuleConfig option - maxNumberOfFunctionParameters:RuleConfig option - maxNumberOfMembers:RuleConfig option - maxNumberOfBooleanOperatorsInCondition:RuleConfig option } -with - member this.Flatten() = - Array.concat - [| - this.maxNumberOfItemsInTuple |> Option.bind (constructRuleWithConfig MaxNumberOfItemsInTuple.rule) |> Option.toArray - this.maxNumberOfFunctionParameters |> Option.bind (constructRuleWithConfig MaxNumberOfFunctionParameters.rule) |> Option.toArray - this.maxNumberOfMembers |> Option.bind (constructRuleWithConfig MaxNumberOfMembers.rule) |> Option.toArray - this.maxNumberOfBooleanOperatorsInCondition |> Option.bind (constructRuleWithConfig MaxNumberOfBooleanOperatorsInCondition.rule) |> Option.toArray - |] - -[] -type BindingConfig = - { favourIgnoreOverLetWild:EnabledConfig option - wildcardNamedWithAsPattern:EnabledConfig option - uselessBinding:EnabledConfig option - tupleOfWildcards:EnabledConfig option - favourAsKeyword:EnabledConfig option - favourTypedIgnore:EnabledConfig option } -with - member this.Flatten() = - Array.concat - [| - this.favourIgnoreOverLetWild |> Option.bind (constructRuleIfEnabled FavourIgnoreOverLetWild.rule) |> Option.toArray - this.favourTypedIgnore |> Option.bind (constructRuleIfEnabled FavourTypedIgnore.rule) |> Option.toArray - this.wildcardNamedWithAsPattern |> Option.bind (constructRuleIfEnabled WildcardNamedWithAsPattern.rule) |> Option.toArray - this.uselessBinding |> Option.bind (constructRuleIfEnabled UselessBinding.rule) |> Option.toArray - this.tupleOfWildcards |> Option.bind (constructRuleIfEnabled TupleOfWildcards.rule) |> Option.toArray - this.favourAsKeyword |> Option.bind (constructRuleIfEnabled FavourAsKeyword.rule) |> Option.toArray - |] - -[] -type ConventionsConfig = - { recursiveAsyncFunction:EnabledConfig option - avoidTooShortNames:EnabledConfig option - indexerAccessorStyleConsistency: RuleConfig option - redundantNewKeyword:EnabledConfig option - favourStaticEmptyFields:EnabledConfig option - asyncExceptionWithoutReturn:EnabledConfig option - unneededRecKeyword:EnabledConfig option - favourNonMutablePropertyInitialization:EnabledConfig option - nestedStatements:RuleConfig option - cyclomaticComplexity:RuleConfig option - reimplementsFunction:EnabledConfig option - canBeReplacedWithComposition:EnabledConfig option - avoidSinglePipeOperator:EnabledConfig option - raiseWithTooManyArgs:RaiseWithTooManyArgsConfig option - sourceLength:SourceLengthConfig option - naming:NamesConfig option - numberOfItems:NumberOfItemsConfig option - binding:BindingConfig option - favourReRaise:EnabledConfig option - favourConsistentThis:RuleConfig option - suggestUseAutoProperty:EnabledConfig option - usedUnderscorePrefixedElements:EnabledConfig option - ensureTailCallDiagnosticsInRecursiveFunctions:EnabledConfig option} -with - member this.Flatten() = - Array.concat - [| - this.recursiveAsyncFunction |> Option.bind (constructRuleIfEnabled RecursiveAsyncFunction.rule) |> Option.toArray - this.avoidTooShortNames |> Option.bind (constructRuleIfEnabled AvoidTooShortNames.rule) |> Option.toArray - this.redundantNewKeyword |> Option.bind (constructRuleIfEnabled RedundantNewKeyword.rule) |> Option.toArray - this.favourNonMutablePropertyInitialization |> Option.bind (constructRuleIfEnabled FavourNonMutablePropertyInitialization.rule) |> Option.toArray - this.favourReRaise |> Option.bind (constructRuleIfEnabled FavourReRaise.rule) |> Option.toArray - this.favourStaticEmptyFields |> Option.bind (constructRuleIfEnabled FavourStaticEmptyFields.rule) |> Option.toArray - this.asyncExceptionWithoutReturn |> Option.bind (constructRuleIfEnabled AsyncExceptionWithoutReturn.rule) |> Option.toArray - this.unneededRecKeyword |> Option.bind (constructRuleIfEnabled UnneededRecKeyword.rule) |> Option.toArray - this.nestedStatements |> Option.bind (constructRuleWithConfig NestedStatements.rule) |> Option.toArray - this.favourConsistentThis |> Option.bind (constructRuleWithConfig FavourConsistentThis.rule) |> Option.toArray - this.cyclomaticComplexity |> Option.bind (constructRuleWithConfig CyclomaticComplexity.rule) |> Option.toArray - this.reimplementsFunction |> Option.bind (constructRuleIfEnabled ReimplementsFunction.rule) |> Option.toArray - this.canBeReplacedWithComposition |> Option.bind (constructRuleIfEnabled CanBeReplacedWithComposition.rule) |> Option.toArray - this.avoidSinglePipeOperator|> Option.bind (constructRuleIfEnabled AvoidSinglePipeOperator.rule) |> Option.toArray - this.usedUnderscorePrefixedElements |> Option.bind (constructRuleIfEnabled UsedUnderscorePrefixedElements.rule) |> Option.toArray - this.raiseWithTooManyArgs |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat - this.sourceLength |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat - this.naming |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat - this.numberOfItems |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat - this.binding |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat - this.suggestUseAutoProperty |> Option.bind (constructRuleIfEnabled SuggestUseAutoProperty.rule) |> Option.toArray - this.ensureTailCallDiagnosticsInRecursiveFunctions |> Option.bind (constructRuleIfEnabled EnsureTailCallDiagnosticsInRecursiveFunctions.rule) |> Option.toArray - this.indexerAccessorStyleConsistency |> Option.bind (constructRuleWithConfig IndexerAccessorStyleConsistency.rule) |> Option.toArray - |] - -[] -type TypographyConfig = - { indentation:EnabledConfig option - maxCharactersOnLine:RuleConfig option - trailingWhitespaceOnLine:RuleConfig option - maxLinesInFile:RuleConfig option - trailingNewLineInFile:EnabledConfig option - noTabCharacters:EnabledConfig option } -with - member this.Flatten() = - Array.concat - [| - this.indentation |> Option.bind (constructRuleIfEnabled Indentation.rule) |> Option.toArray - this.maxCharactersOnLine |> Option.bind (constructRuleWithConfig MaxCharactersOnLine.rule) |> Option.toArray - this.trailingWhitespaceOnLine |> Option.bind (constructRuleWithConfig TrailingWhitespaceOnLine.rule) |> Option.toArray - this.maxLinesInFile |> Option.bind (constructRuleWithConfig MaxLinesInFile.rule) |> Option.toArray - this.trailingNewLineInFile |> Option.bind (constructRuleIfEnabled TrailingNewLineInFile.rule) |> Option.toArray - this.noTabCharacters |> Option.bind (constructRuleIfEnabled NoTabCharacters.rule) |> Option.toArray - |] - -// - let private getOrEmptyList hints = Option.defaultValue Array.empty hints type HintConfig = { - add:string [] option - ignore:string [] option + Add:string [] option + Ignore:string [] option } type GlobalConfig = { - numIndentationSpaces:int option + NumIndentationSpaces:int option } type Configuration = { Global:GlobalConfig option - // Deprecated grouped configs. TODO: remove in next major release - - [] - /// DEPRECATED, provide formatting rules at root level. - formatting:FormattingConfig option - [] - /// DEPRECATED, provide conventions rules at root level. - conventions:ConventionsConfig option - /// DEPRECATED, provide typography rules at root level. - [] - typography:TypographyConfig option - - // - - ignoreFiles:string [] option + IgnoreFiles:string [] option Hints:HintConfig option TypedItemSpacing:RuleConfig option TypePrefixing:RuleConfig option @@ -471,7 +183,7 @@ type Configuration = PatternMatchClauseIndentation:RuleConfig option PatternMatchExpressionIndentation:EnabledConfig option RecursiveAsyncFunction:EnabledConfig option - AvoidTooShortNames:EnabledConfig option + AvoidTooShortNaming:EnabledConfig option IndexerAccessorStyleConsistency:RuleConfig option RedundantNewKeyword:EnabledConfig option FavourNonMutablePropertyInitialization:EnabledConfig option @@ -520,7 +232,6 @@ type Configuration = MeasureTypeNames:RuleConfig option ActivePatternNames:RuleConfig option PublicValuesNames:RuleConfig option - NonPublicValuesNames:RuleConfig option PrivateValuesNames:RuleConfig option InternalValuesNames:RuleConfig option UnnestedFunctionNames:RuleConfig option @@ -549,15 +260,9 @@ type Configuration = with static member Zero = { Global = None - ignoreFiles = None + IgnoreFiles = None Hints = None - // Deprecated grouped configs. TODO: remove in next major release - formatting = None - conventions = None - typography = None - // - // Configs for rules. TypedItemSpacing = None TypePrefixing = None @@ -572,7 +277,7 @@ with PatternMatchClauseIndentation = None PatternMatchExpressionIndentation = None RecursiveAsyncFunction = None - AvoidTooShortNames = None + AvoidTooShortNaming = None IndexerAccessorStyleConsistency = None RedundantNewKeyword = None FavourNonMutablePropertyInitialization = None @@ -621,7 +326,6 @@ with MeasureTypeNames = None ActivePatternNames = None PublicValuesNames = None - NonPublicValuesNames = None PrivateValuesNames = None InternalValuesNames = None UnnestedFunctionNames = None @@ -649,8 +353,6 @@ with FavourSingleton = None } -// fsharplint:enable RecordFieldNames - /// Tries to parse the provided config text. let parseConfig (configText:string) = try @@ -687,12 +389,12 @@ type LoadedRules = { GlobalConfig:Rules.GlobalRuleConfig AstNodeRules:RuleMetadata [] LineRules:LineRules - DeprecatedRules:Rule [] } + } let getGlobalConfig (globalConfig:GlobalConfig option) = globalConfig |> Option.map (fun globalConfig -> { - Rules.GlobalRuleConfig.numIndentationSpaces = globalConfig.numIndentationSpaces |> Option.defaultValue Rules.GlobalRuleConfig.Default.numIndentationSpaces + Rules.GlobalRuleConfig.NumIndentationSpaces = globalConfig.NumIndentationSpaces |> Option.defaultValue Rules.GlobalRuleConfig.Default.NumIndentationSpaces }) |> Option.defaultValue Rules.GlobalRuleConfig.Default let private parseHints (hints:string []) = @@ -708,57 +410,14 @@ let private parseHints (hints:string []) = |> Array.toList |> MergeSyntaxTrees.mergeHints -let findDeprecation config deprecatedAllRules allRules = - if config.NonPublicValuesNames.IsSome && - (config.PrivateValuesNames.IsSome || config.InternalValuesNames.IsSome) then - failwith "nonPublicValuesNames has been deprecated, use privateValuesNames and/or internalValuesNames instead" - - let astNodeRules = ResizeArray() - let lineRules = ResizeArray() - let mutable indentationRule = None - let mutable noTabCharactersRule = None - Array.append allRules deprecatedAllRules - |> Array.distinctBy (function // Discard any deprecated rules which were define in a non-deprecated form. - | Rule.AstNodeRule rule -> rule.Identifier - | Rule.LineRule rule -> rule.Identifier - | Rule.IndentationRule rule -> rule.Identifier - | Rule.NoTabCharactersRule rule -> rule.Identifier) - |> Array.iter (function - | AstNodeRule rule -> astNodeRules.Add rule - | LineRule rule -> lineRules.Add(rule) - | IndentationRule rule -> indentationRule <- Some rule - | NoTabCharactersRule rule -> noTabCharactersRule <- Some rule) - - { - LoadedRules.GlobalConfig = getGlobalConfig config.Global - DeprecatedRules = deprecatedAllRules - AstNodeRules = astNodeRules.ToArray() - LineRules = - { - GenericLineRules = lineRules.ToArray() - IndentationRule = indentationRule - NoTabCharactersRule = noTabCharactersRule - } - } - // fsharplint:disable MaxLinesInFunction let flattenConfig (config:Configuration) = - let deprecatedAllRules = - Array.concat - [| - // Deprecated grouped configs. TODO: remove in next major release - config.formatting |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat - config.conventions |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat - config.typography |> Option.map (fun config -> config.Flatten()) |> Option.toArray |> Array.concat - // - - config.Hints |> Option.map (fun config -> HintMatcher.rule { HintMatcher.Config.HintTrie = parseHints (getOrEmptyList config.add) }) |> Option.toArray - |] - let allRules = Array.choose id [| + config.Hints |> Option.map (fun config -> HintMatcher.rule { HintMatcher.Config.HintTrie = parseHints (getOrEmptyList config.Add) }) + config.TypedItemSpacing |> Option.bind (constructRuleWithConfig TypedItemSpacing.rule) config.TypePrefixing |> Option.bind (constructTypePrefixingRuleWithConfig TypePrefixing.rule) config.UnionDefinitionIndentation |> Option.bind (constructRuleIfEnabled UnionDefinitionIndentation.rule) @@ -772,7 +431,7 @@ let flattenConfig (config:Configuration) = config.PatternMatchClauseIndentation |> Option.bind (constructRuleWithConfig PatternMatchClauseIndentation.rule) config.PatternMatchExpressionIndentation |> Option.bind (constructRuleIfEnabled PatternMatchExpressionIndentation.rule) config.RecursiveAsyncFunction |> Option.bind (constructRuleIfEnabled RecursiveAsyncFunction.rule) - config.AvoidTooShortNames |> Option.bind (constructRuleIfEnabled AvoidTooShortNames.rule) + config.AvoidTooShortNaming |> Option.bind (constructRuleIfEnabled AvoidTooShortNaming.rule) config.IndexerAccessorStyleConsistency |> Option.bind (constructRuleWithConfig IndexerAccessorStyleConsistency.rule) config.RedundantNewKeyword |> Option.bind (constructRuleIfEnabled RedundantNewKeyword.rule) config.FavourNonMutablePropertyInitialization |> Option.bind (constructRuleIfEnabled FavourNonMutablePropertyInitialization.rule) @@ -821,8 +480,6 @@ let flattenConfig (config:Configuration) = config.MeasureTypeNames |> Option.bind (constructRuleWithConfig MeasureTypeNames.rule) config.ActivePatternNames |> Option.bind (constructRuleWithConfig ActivePatternNames.rule) config.PublicValuesNames |> Option.bind (constructRuleWithConfig PublicValuesNames.rule) - config.NonPublicValuesNames |> Option.bind (constructRuleWithConfig PrivateValuesNames.rule) - config.NonPublicValuesNames |> Option.bind (constructRuleWithConfig InternalValuesNames.rule) config.PrivateValuesNames |> Option.bind (constructRuleWithConfig PrivateValuesNames.rule) config.InternalValuesNames |> Option.bind (constructRuleWithConfig InternalValuesNames.rule) config.UnnestedFunctionNames |> Option.bind (constructRuleWithConfig UnnestedFunctionNames.rule) @@ -850,4 +507,26 @@ let flattenConfig (config:Configuration) = config.FavourSingleton |> Option.bind (constructRuleIfEnabled FavourSingleton.rule) |] - findDeprecation config deprecatedAllRules allRules + let astNodeRules = ResizeArray() + let lineRules = ResizeArray() + let mutable indentationRule = None + let mutable noTabCharactersRule = None + + allRules + |> Array.iter (function + | AstNodeRule rule -> astNodeRules.Add rule + | LineRule rule -> lineRules.Add(rule) + | IndentationRule rule -> indentationRule <- Some rule + | NoTabCharactersRule rule -> noTabCharactersRule <- Some rule) + + { + LoadedRules.GlobalConfig = getGlobalConfig config.Global + AstNodeRules = astNodeRules.ToArray() + LineRules = + { + GenericLineRules = lineRules.ToArray() + IndentationRule = indentationRule + NoTabCharactersRule = noTabCharactersRule + } + } +// fsharplint:enable MaxLinesInFunction diff --git a/src/FSharpLint.Core/Application/Lint.fs b/src/FSharpLint.Core/Application/Lint.fs index da988cc96..24193d2d4 100644 --- a/src/FSharpLint.Core/Application/Lint.fs +++ b/src/FSharpLint.Core/Application/Lint.fs @@ -467,7 +467,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) diff --git a/src/FSharpLint.Core/FSharpLint.Core.fsproj b/src/FSharpLint.Core/FSharpLint.Core.fsproj index 86bb8d7e8..dd43791ae 100644 --- a/src/FSharpLint.Core/FSharpLint.Core.fsproj +++ b/src/FSharpLint.Core/FSharpLint.Core.fsproj @@ -118,7 +118,7 @@ - + diff --git a/src/FSharpLint.Core/Framework/Rules.fs b/src/FSharpLint.Core/Framework/Rules.fs index 2877244ab..f6f6e94f5 100644 --- a/src/FSharpLint.Core/Framework/Rules.fs +++ b/src/FSharpLint.Core/Framework/Rules.fs @@ -7,18 +7,15 @@ 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 + GlobalRuleConfig.NumIndentationSpaces = 4 } -// fsharplint:enable RecordFieldNames type AstNodeRuleParams = { AstNode:AstNode diff --git a/src/FSharpLint.Core/Rules/Conventions/Naming/AvoidTooShortNames.fs b/src/FSharpLint.Core/Rules/Conventions/Naming/AvoidTooShortNaming.fs similarity index 95% rename from src/FSharpLint.Core/Rules/Conventions/Naming/AvoidTooShortNames.fs rename to src/FSharpLint.Core/Rules/Conventions/Naming/AvoidTooShortNaming.fs index 5c7f04171..61cb73e00 100644 --- a/src/FSharpLint.Core/Rules/Conventions/Naming/AvoidTooShortNames.fs +++ b/src/FSharpLint.Core/Rules/Conventions/Naming/AvoidTooShortNaming.fs @@ -1,4 +1,4 @@ -module FSharpLint.Rules.AvoidTooShortNames +module FSharpLint.Rules.AvoidTooShortNaming open System open FSharp.Compiler.Syntax @@ -15,7 +15,7 @@ let private checkIdentifierPart (identifier:Ident) (idText:string) = let formatError errorName = String.Format(Resources.GetString errorName, idText) - "RulesAvoidTooShortNamesError" |> formatError |> Array.singleton + "RulesAvoidTooShortNamingError" |> formatError |> Array.singleton let private checkIdentifier (identifier:Ident) (idText:string) = if isIdentifierTooShort idText then @@ -105,8 +105,8 @@ let runner (args:AstNodeRuleParams) = let rule = AstNodeRule { - Name = "AvoidTooShortNames" - Identifier = Identifiers.AvoidTooShortNames + Name = "AvoidTooShortNaming" + Identifier = Identifiers.AvoidTooShortNaming RuleConfig = { AstNodeRuleConfig.Runner = runner diff --git a/src/FSharpLint.Core/Rules/Formatting/PatternMatchFormatting/PatternMatchClauseIndentation.fs b/src/FSharpLint.Core/Rules/Formatting/PatternMatchFormatting/PatternMatchClauseIndentation.fs index 1e921c4ce..23c8880ad 100644 --- a/src/FSharpLint.Core/Rules/Formatting/PatternMatchFormatting/PatternMatchClauseIndentation.fs +++ b/src/FSharpLint.Core/Rules/Formatting/PatternMatchFormatting/PatternMatchClauseIndentation.fs @@ -19,7 +19,7 @@ let check (config:Config) (args:AstNodeRuleParams) matchExprRange (clauses:SynMa let processClause (firstClause: SynMatchClause) = 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 Some { Range = firstClause.Range diff --git a/src/FSharpLint.Core/Rules/Formatting/PatternMatchFormatting/PatternMatchExpressionIndentation.fs b/src/FSharpLint.Core/Rules/Formatting/PatternMatchFormatting/PatternMatchExpressionIndentation.fs index b398fbd45..058647299 100644 --- a/src/FSharpLint.Core/Rules/Formatting/PatternMatchFormatting/PatternMatchExpressionIndentation.fs +++ b/src/FSharpLint.Core/Rules/Formatting/PatternMatchFormatting/PatternMatchExpressionIndentation.fs @@ -17,7 +17,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 Some { Range = expr.Range diff --git a/src/FSharpLint.Core/Rules/Formatting/Typography/Indentation.fs b/src/FSharpLint.Core/Rules/Formatting/Typography/Indentation.fs index a9d9372bf..a7dd5ef10 100644 --- a/src/FSharpLint.Core/Rules/Formatting/Typography/Indentation.fs +++ b/src/FSharpLint.Core/Rules/Formatting/Typography/Indentation.fs @@ -181,7 +181,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 = diff --git a/src/FSharpLint.Core/Rules/Formatting/Typography/NoTabCharacters.fs b/src/FSharpLint.Core/Rules/Formatting/Typography/NoTabCharacters.fs index 4fa34d427..55636a1a6 100644 --- a/src/FSharpLint.Core/Rules/Formatting/Typography/NoTabCharacters.fs +++ b/src/FSharpLint.Core/Rules/Formatting/Typography/NoTabCharacters.fs @@ -35,7 +35,7 @@ let checkNoTabCharacters literalStrings (args:LineRuleParams) = (Some( { FromRange = range FromText = "\t" - ToText = String.replicate args.GlobalConfig.numIndentationSpaces " " } + ToText = String.replicate args.GlobalConfig.NumIndentationSpaces " " } )) ) TypeChecks = List.Empty } diff --git a/src/FSharpLint.Core/Rules/Formatting/UnionDefinitionIndentation.fs b/src/FSharpLint.Core/Rules/Formatting/UnionDefinitionIndentation.fs index 5a4aa75bd..12b891699 100644 --- a/src/FSharpLint.Core/Rules/Formatting/UnionDefinitionIndentation.fs +++ b/src/FSharpLint.Core/Rules/Formatting/UnionDefinitionIndentation.fs @@ -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 Some { Range = firstCase.Range diff --git a/src/FSharpLint.Core/Rules/Identifiers.fs b/src/FSharpLint.Core/Rules/Identifiers.fs index 910e968d6..49e3d481e 100644 --- a/src/FSharpLint.Core/Rules/Identifiers.fs +++ b/src/FSharpLint.Core/Rules/Identifiers.fs @@ -79,7 +79,7 @@ let CyclomaticComplexity = identifier 71 let FailwithBadUsage = identifier 72 let FavourReRaise = identifier 73 let FavourConsistentThis = identifier 74 -let AvoidTooShortNames = identifier 75 +let AvoidTooShortNaming = identifier 75 let FavourStaticEmptyFields = identifier 76 let AvoidSinglePipeOperator = identifier 77 let AsyncExceptionWithoutReturn = identifier 78 diff --git a/src/FSharpLint.Core/Text.resx b/src/FSharpLint.Core/Text.resx index 92b713b3b..2d990c91b 100644 --- a/src/FSharpLint.Core/Text.resx +++ b/src/FSharpLint.Core/Text.resx @@ -183,7 +183,7 @@ Consider changing `{0}` to lowercase. - + Consider using a longer name, as it is currently too short. diff --git a/src/FSharpLint.Core/fsharplint.json b/src/FSharpLint.Core/fsharplint.json index 3f7e1c858..6c475f8c6 100644 --- a/src/FSharpLint.Core/fsharplint.json +++ b/src/FSharpLint.Core/fsharplint.json @@ -296,7 +296,7 @@ } }, "suggestUseAutoProperty": { "enabled": false }, - "avoidTooShortNames": { "enabled": false }, + "avoidTooShortNaming": { "enabled": false }, "asyncExceptionWithoutReturn": { "enabled": false }, "unneededRecKeyword": { "enabled": true }, "indentation": { diff --git a/tests/FSharpLint.Core.Tests/FSharpLint.Core.Tests.fsproj b/tests/FSharpLint.Core.Tests/FSharpLint.Core.Tests.fsproj index b376875d1..4e6e9b8a9 100644 --- a/tests/FSharpLint.Core.Tests/FSharpLint.Core.Tests.fsproj +++ b/tests/FSharpLint.Core.Tests/FSharpLint.Core.Tests.fsproj @@ -41,7 +41,6 @@ - @@ -49,6 +48,7 @@ + diff --git a/tests/FSharpLint.Core.Tests/Rules/Conventions/AvoidTooShortNames.fs b/tests/FSharpLint.Core.Tests/Rules/Conventions/Naming/AvoidTooShortNaming.fs similarity index 73% rename from tests/FSharpLint.Core.Tests/Rules/Conventions/AvoidTooShortNames.fs rename to tests/FSharpLint.Core.Tests/Rules/Conventions/Naming/AvoidTooShortNaming.fs index 894518291..cc46ea28b 100644 --- a/tests/FSharpLint.Core.Tests/Rules/Conventions/AvoidTooShortNames.fs +++ b/tests/FSharpLint.Core.Tests/Rules/Conventions/Naming/AvoidTooShortNaming.fs @@ -1,4 +1,4 @@ -module FSharpLint.Core.Tests.Rules.Conventions.AvoidTooShortNames +module FSharpLint.Core.Tests.Rules.Conventions.AvoidTooShortNaming open NUnit.Framework open FSharpLint.Framework.Rules @@ -6,11 +6,11 @@ open FSharpLint.Rules open FSharpLint.Core.Tests [] -type TestConventionsAvoidTooShortNames() = - inherit TestAstNodeRuleBase.TestAstNodeRuleBase(AvoidTooShortNames.rule) +type TestConventionsAvoidTooShortNaming() = + inherit TestAstNodeRuleBase.TestAstNodeRuleBase(AvoidTooShortNaming.rule) [] - member this.AvoidTooShortNamesShouldNotProduceError1() = + member this.ShouldNotProduceError1() = this.Parse """ module Program @@ -23,7 +23,7 @@ let bar baz = Assert.IsTrue this.NoErrorsExist [] - member this.AvoidTooShortNamesShouldProduceError2() = + member this.ShouldProduceError2() = this.Parse """ module Program @@ -36,7 +36,7 @@ let bar baz = Assert.IsTrue this.ErrorsExist [] - member this.AvoidTooShortNamesShouldProduceError3() = + member this.ShouldProduceError3() = this.Parse """ module Program @@ -49,7 +49,7 @@ let b baz n = Assert.IsTrue this.ErrorsExist [] - member this.AvoidTooShortNamesShouldProduceError4() = + member this.ShouldProduceError4() = this.Parse """ module Program @@ -62,7 +62,7 @@ let bar b = Assert.IsTrue this.ErrorsExist [] - member this.AvoidTooShortNamesShouldProduceError5() = + member this.ShouldProduceError5() = this.Parse """ module Program @@ -75,7 +75,7 @@ let bar baz = Assert.IsTrue this.ErrorsExist [] - member this.AvoidTooShortNamesShouldProduceError6() = + member this.ShouldProduceError6() = this.Parse """ type CellCreatedFast = private @@ -88,7 +88,7 @@ type CellCreatedFast = Assert.IsTrue this.ErrorsExist [] - member this.AvoidTooShortNamesShouldProduceError7() = + member this.ShouldProduceError7() = this.Parse """ type TorStreamCipher(keyBytes: array, ivOpt: Option>) = member self.Encrypt(data: array) : array = @@ -103,21 +103,21 @@ type TorStreamCipher(keyBytes: array, ivOpt: Option>) = Assert.IsTrue this.ErrorsExist [] - member this.AvoidTooShortNamesShouldProduceError8() = + member this.ShouldProduceError8() = this.Parse """ type Foo<'T> = Option<'T> """ Assert.IsTrue this.ErrorsExist [] - member this.AvoidTooShortNamesShouldProduceError9() = + member this.ShouldProduceError9() = this.Parse """ type Foo<'SomeType> = Option<'SomeType> """ this.AssertNoWarnings() [] - member this.AvoidTooShortNamesShouldProduceError10() = + member this.ShouldProduceError10() = this.Parse """ let Foo (x: int) = x.ToString() @@ -125,7 +125,7 @@ let Foo (x: int) = Assert.IsTrue this.ErrorsExist [] - member this.AvoidTooShortNamesShouldProduceError11() = + member this.ShouldProduceError11() = this.Parse """ match foo with | x -> () @@ -133,7 +133,7 @@ match foo with Assert.IsTrue this.ErrorsExist [] - member this.AvoidTooShortNamesShouldProduceError12() = + member this.ShouldProduceError12() = this.Parse """ match foo with | Some(x) -> () @@ -141,7 +141,7 @@ match foo with Assert.IsTrue this.ErrorsExist [] - member this.AvoidTooShortNamesShouldProduceError13() = + member this.ShouldProduceError13() = this.Parse """ match foo with | Some(x) -> (x) @@ -150,7 +150,7 @@ match foo with Assert.IsFalse(this.ErrorExistsAt(3, 14)) [] - member this.AvoidTooShortNamesShouldProduceError14() = + member this.ShouldProduceError14() = this.Parse """ async { let! z = async { return 1 + 2 } @@ -161,7 +161,7 @@ async { Assert.IsTrue this.ErrorsExist [] - member this.AvoidTooShortNamesShouldProduceError15() = + member this.ShouldProduceError15() = this.Parse """ async { let! result = async { return 1 + 2 } @@ -172,7 +172,7 @@ async { Assert.IsTrue this.NoErrorsExist [] - member this.AvoidTooShortNamesShouldProduceError16() = + member this.ShouldProduceError16() = this.Parse """ type SomeDU = | SomeMember of int * string * bool @@ -187,7 +187,7 @@ let fooFunction (arg: SomeDU) = Assert.IsTrue this.ErrorsExist [] - member this.AvoidTooShortNamesShouldProduceError17() = + member this.ShouldProduceError17() = this.Parse """ fun x -> x + 1 |> ignore """