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
2 changes: 1 addition & 1 deletion docs/content/how-tos/rule-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions docs/content/how-tos/rules/FL0075.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -23,7 +23,7 @@ Use longer names for the flagged occurrences.
## Rule Settings

{
"avoidTooShortNames": {
"avoidTooShortNaming": {
"enabled": false
}
}
391 changes: 35 additions & 356 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 @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/FSharpLint.Core/FSharpLint.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<Compile Include="Rules\Conventions\Binding\UselessBinding.fs" />
<Compile Include="Rules\Conventions\Binding\TupleOfWildcards.fs" />
<Compile Include="Rules\Conventions\Binding\FavourAsKeyword.fs" />
<Compile Include="Rules\Conventions\Naming\AvoidTooShortNames.fs" />
<Compile Include="Rules\Conventions\Naming\AvoidTooShortNaming.fs" />
<Compile Include="Rules\Formatting\Typography\Indentation.fs" />
<Compile Include="Rules\Formatting\Typography\MaxCharactersOnLine.fs" />
<Compile Include="Rules\Formatting\Typography\TrailingWhitespaceOnLine.fs" />
Expand Down
7 changes: 2 additions & 5 deletions src/FSharpLint.Core/Framework/Rules.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module FSharpLint.Rules.AvoidTooShortNames
module FSharpLint.Rules.AvoidTooShortNaming

open System
open FSharp.Compiler.Syntax
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
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
Some
{
Range = firstCase.Range
Expand Down
2 changes: 1 addition & 1 deletion src/FSharpLint.Core/Rules/Identifiers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/FSharpLint.Core/Text.resx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
<data name="RulesNamingConventionsLowercaseError" xml:space="preserve">
<value>Consider changing `{0}` to lowercase.</value>
</data>
<data name="RulesAvoidTooShortNamesError" xml:space="preserve">
<data name="RulesAvoidTooShortNamingError" xml:space="preserve">
<value>Consider using a longer name, as it is currently too short.</value>
</data>
<data name="RulesNamingConventionsPrefixError" xml:space="preserve">
Expand Down
2 changes: 1 addition & 1 deletion src/FSharpLint.Core/fsharplint.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
}
},
"suggestUseAutoProperty": { "enabled": false },
"avoidTooShortNames": { "enabled": false },
"avoidTooShortNaming": { "enabled": false },
"asyncExceptionWithoutReturn": { "enabled": false },
"unneededRecKeyword": { "enabled": true },
"indentation": {
Expand Down
2 changes: 1 addition & 1 deletion tests/FSharpLint.Core.Tests/FSharpLint.Core.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
<Compile Include="Rules\Conventions\NoPartialFunctions.fs" />
<Compile Include="Rules\Conventions\FavourReRaise.fs" />
<Compile Include="Rules\Conventions\FavourConsistentThis.fs" />
<Compile Include="Rules\Conventions\AvoidTooShortNames.fs" />
<Compile Include="Rules\Conventions\AvoidSinglePipeOperator.fs" />
<Compile Include="Rules\Conventions\SuggestUseAutoProperty.fs" />
<Compile Include="Rules\Conventions\UsedUnderscorePrefixedElements.fs" />
<Compile Include="Rules\Conventions\FavourNonMutablePropertyInitialization.fs" />
<Compile Include="Rules\Conventions\EnsureTailCallDiagnosticsInRecursiveFunctions.fs" />
<Compile Include="Rules\Conventions\IndexerAccessorStyleConsistency.fs" />
<Compile Include="Rules\Conventions\FavourSingleton.fs" />
<Compile Include="Rules\Conventions\Naming\AvoidTooShortNaming.fs" />
<Compile Include="Rules\Conventions\Naming\NamingHelpers.fs" />
<Compile Include="Rules\Conventions\Naming\InterfaceNames.fs" />
<Compile Include="Rules\Conventions\Naming\ExceptionNames.fs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module FSharpLint.Core.Tests.Rules.Conventions.AvoidTooShortNames
module FSharpLint.Core.Tests.Rules.Conventions.AvoidTooShortNaming

open NUnit.Framework
open FSharpLint.Framework.Rules
open FSharpLint.Rules
open FSharpLint.Core.Tests

[<TestFixture>]
type TestConventionsAvoidTooShortNames() =
inherit TestAstNodeRuleBase.TestAstNodeRuleBase(AvoidTooShortNames.rule)
type TestConventionsAvoidTooShortNaming() =
inherit TestAstNodeRuleBase.TestAstNodeRuleBase(AvoidTooShortNaming.rule)

[<Test>]
member this.AvoidTooShortNamesShouldNotProduceError1() =
member this.ShouldNotProduceError1() =
this.Parse """
module Program

Expand All @@ -23,7 +23,7 @@ let bar baz =
Assert.IsTrue this.NoErrorsExist

[<Test>]
member this.AvoidTooShortNamesShouldProduceError2() =
member this.ShouldProduceError2() =
this.Parse """
module Program

Expand All @@ -36,7 +36,7 @@ let bar baz =
Assert.IsTrue this.ErrorsExist

[<Test>]
member this.AvoidTooShortNamesShouldProduceError3() =
member this.ShouldProduceError3() =
this.Parse """
module Program

Expand All @@ -49,7 +49,7 @@ let b baz n =
Assert.IsTrue this.ErrorsExist

[<Test>]
member this.AvoidTooShortNamesShouldProduceError4() =
member this.ShouldProduceError4() =
this.Parse """
module Program

Expand All @@ -62,7 +62,7 @@ let bar b =
Assert.IsTrue this.ErrorsExist

[<Test>]
member this.AvoidTooShortNamesShouldProduceError5() =
member this.ShouldProduceError5() =
this.Parse """
module Program

Expand All @@ -75,7 +75,7 @@ let bar baz =
Assert.IsTrue this.ErrorsExist

[<Test>]
member this.AvoidTooShortNamesShouldProduceError6() =
member this.ShouldProduceError6() =
this.Parse """
type CellCreatedFast =
private
Expand All @@ -88,7 +88,7 @@ type CellCreatedFast =
Assert.IsTrue this.ErrorsExist

[<Test>]
member this.AvoidTooShortNamesShouldProduceError7() =
member this.ShouldProduceError7() =
this.Parse """
type TorStreamCipher(keyBytes: array<byte>, ivOpt: Option<array<byte>>) =
member self.Encrypt(data: array<byte>) : array<byte> =
Expand All @@ -103,45 +103,45 @@ type TorStreamCipher(keyBytes: array<byte>, ivOpt: Option<array<byte>>) =
Assert.IsTrue this.ErrorsExist

[<Test>]
member this.AvoidTooShortNamesShouldProduceError8() =
member this.ShouldProduceError8() =
this.Parse """
type Foo<'T> = Option<'T>
"""
Assert.IsTrue this.ErrorsExist

[<Test>]
member this.AvoidTooShortNamesShouldProduceError9() =
member this.ShouldProduceError9() =
this.Parse """
type Foo<'SomeType> = Option<'SomeType>
"""
this.AssertNoWarnings()

[<Test>]
member this.AvoidTooShortNamesShouldProduceError10() =
member this.ShouldProduceError10() =
this.Parse """
let Foo (x: int) =
x.ToString()
"""
Assert.IsTrue this.ErrorsExist

[<Test>]
member this.AvoidTooShortNamesShouldProduceError11() =
member this.ShouldProduceError11() =
this.Parse """
match foo with
| x -> ()
"""
Assert.IsTrue this.ErrorsExist

[<Test>]
member this.AvoidTooShortNamesShouldProduceError12() =
member this.ShouldProduceError12() =
this.Parse """
match foo with
| Some(x) -> ()
"""
Assert.IsTrue this.ErrorsExist

[<Test>]
member this.AvoidTooShortNamesShouldProduceError13() =
member this.ShouldProduceError13() =
this.Parse """
match foo with
| Some(x) -> (x)
Expand All @@ -150,7 +150,7 @@ match foo with
Assert.IsFalse(this.ErrorExistsAt(3, 14))

[<Test>]
member this.AvoidTooShortNamesShouldProduceError14() =
member this.ShouldProduceError14() =
this.Parse """
async {
let! z = async { return 1 + 2 }
Expand All @@ -161,7 +161,7 @@ async {
Assert.IsTrue this.ErrorsExist

[<Test>]
member this.AvoidTooShortNamesShouldProduceError15() =
member this.ShouldProduceError15() =
this.Parse """
async {
let! result = async { return 1 + 2 }
Expand All @@ -172,7 +172,7 @@ async {
Assert.IsTrue this.NoErrorsExist

[<Test>]
member this.AvoidTooShortNamesShouldProduceError16() =
member this.ShouldProduceError16() =
this.Parse """
type SomeDU =
| SomeMember of int * string * bool
Expand All @@ -187,7 +187,7 @@ let fooFunction (arg: SomeDU) =
Assert.IsTrue this.ErrorsExist

[<Test>]
member this.AvoidTooShortNamesShouldProduceError17() =
member this.ShouldProduceError17() =
this.Parse """
fun x -> x + 1 |> ignore
"""
Expand Down
Loading