Skip to content

Commit 14fe636

Browse files
webwarrior-wsknocte
authored andcommitted
Conventions/Naming: renamed Accessibility DU to AccessControlLevel
Also added comment
1 parent 781908b commit 14fe636

File tree

7 files changed

+28
-23
lines changed

7 files changed

+28
-23
lines changed

src/FSharpLint.Core/Rules/Conventions/Naming/ActivePatternNames.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let private getValueOrFunctionIdents _ pattern =
2525
let private getIdentifiers (args:AstNodeRuleParams) =
2626
match args.AstNode with
2727
| AstNode.Expression(SynExpr.ForEach(_, _, true, pattern, _, _, _)) ->
28-
getPatternIdents Accessibility.Private getValueOrFunctionIdents false pattern
28+
getPatternIdents AccessControlLevel.Private getValueOrFunctionIdents false pattern
2929
| AstNode.Binding(SynBinding(_, _, _, _, attributes, _, valData, pattern, _, _, _, _)) ->
3030
if not (isLiteral attributes) then
3131
match identifierTypeFromValData valData with

src/FSharpLint.Core/Rules/Conventions/Naming/InternalValuesNames.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let private getValueOrFunctionIdents typeChecker isPublic pattern =
2020
match List.tryLast longIdent.Lid with
2121
| Some ident when not (isActivePattern ident) && singleIdentifier ->
2222
let checkNotUnionCase = checkNotUnionCase ident
23-
if isPublic = Accessibility.Internal then
23+
if isPublic = AccessControlLevel.Internal then
2424
(ident, ident.idText, Some checkNotUnionCase)
2525
|> Array.singleton
2626
else

src/FSharpLint.Core/Rules/Conventions/Naming/MemberNames.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ let private getIdentifiers (args:AstNodeRuleParams) =
2929
if not (isLiteral attributes) && not (isImplementingInterface parents) then
3030
match identifierTypeFromValData valData with
3131
| Member | Property ->
32-
getPatternIdents Accessibility.Private getMemberIdents true pattern
32+
getPatternIdents AccessControlLevel.Private getMemberIdents true pattern
3333
| _ -> Array.empty
3434
else
3535
Array.empty

src/FSharpLint.Core/Rules/Conventions/Naming/NamingHelper.fs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,21 @@ let activePatternIdentifiers (identifier:Ident) =
179179
|> Array.filter (fun x -> not <| String.IsNullOrEmpty(x) && x.Trim() <> "_")
180180

181181

182-
type Accessibility =
182+
/// Specifies access control level as described in
183+
/// https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/access-control .
184+
/// Higher levels also include lower levels, so e.g. identifier marked with Public
185+
/// is also accessible in Internal and Private scopes.
186+
/// Public scope is the widest, then goes Internal, then Private.
187+
type AccessControlLevel =
183188
| Public
184189
| Private
185190
| Internal
186191

187192
let getAccessibility (syntaxArray:AbstractSyntaxArray.Node []) i =
188193
let isSynAccessPublic = function
189-
| Some(SynAccess.Public) | None -> Accessibility.Public
190-
| Some(SynAccess.Private) -> Accessibility.Private
191-
| Some(SynAccess.Internal) -> Accessibility.Internal
194+
| Some(SynAccess.Public) | None -> AccessControlLevel.Public
195+
| Some(SynAccess.Private) -> AccessControlLevel.Private
196+
| Some(SynAccess.Internal) -> AccessControlLevel.Internal
192197

193198
let rec getAccessibility state isPrivateWhenReachedBinding i =
194199
if i = 0 then state
@@ -206,12 +211,12 @@ let getAccessibility (syntaxArray:AbstractSyntaxArray.Node []) i =
206211
| Pattern(SynPat.LongIdent(_, _, _, _, access, _)) ->
207212
getAccessibility (isSynAccessPublic access) isPrivateWhenReachedBinding node.ParentIndex
208213
| TypeSimpleRepresentation(_)
209-
| Pattern(_) -> Accessibility.Public
214+
| Pattern(_) -> AccessControlLevel.Public
210215
| MemberDefinition(_) ->
211-
if isPrivateWhenReachedBinding then Accessibility.Private
216+
if isPrivateWhenReachedBinding then AccessControlLevel.Private
212217
else getAccessibility state isPrivateWhenReachedBinding node.ParentIndex
213218
| Binding(SynBinding(access, _, _, _, _, _, _, _, _, _, _, _)) ->
214-
if isPrivateWhenReachedBinding then Accessibility.Private
219+
if isPrivateWhenReachedBinding then AccessControlLevel.Private
215220
else getAccessibility (isSynAccessPublic access) true node.ParentIndex
216221
| EnumCase(_)
217222
| TypeRepresentation(_)
@@ -231,7 +236,7 @@ let getAccessibility (syntaxArray:AbstractSyntaxArray.Node []) i =
231236
| LambdaBody(_)
232237
| Expression(_) -> getAccessibility state true node.ParentIndex
233238

234-
getAccessibility Accessibility.Public false i
239+
getAccessibility AccessControlLevel.Public false i
235240

236241

237242
/// Is an attribute with a given name?
@@ -282,8 +287,8 @@ let isInterface typeDef =
282287

283288
let checkAccessibility currentAccessibility = function
284289
| Some(SynAccess.Public) | None -> currentAccessibility
285-
| Some(SynAccess.Private) -> Accessibility.Private
286-
| Some(SynAccess.Internal) -> Accessibility.Internal
290+
| Some(SynAccess.Private) -> AccessControlLevel.Private
291+
| Some(SynAccess.Internal) -> AccessControlLevel.Internal
287292

288293
let isModule (moduleKind:SynModuleOrNamespaceKind) =
289294
match moduleKind with
@@ -302,11 +307,11 @@ let isImplicitModule (SynModuleOrNamespace.SynModuleOrNamespace(longIdent, _, mo
302307
// TODO: does SynModuleOrNamespaceKind.AnonModule replace this check?
303308
isModule moduleKind && longIdent |> List.forall (fun x -> zeroLengthRange x.idRange)
304309

305-
type GetIdents<'t> = Accessibility -> SynPat -> 't []
310+
type GetIdents<'t> = AccessControlLevel -> SynPat -> 't []
306311

307312
/// Recursively get all identifiers from pattern using provided getIdents function and collect them into array.
308313
/// accessibility parameter is passed to getIdents, and can be narrowed down along the way (see checkAccessibility).
309-
let rec getPatternIdents<'t> (accessibility:Accessibility) (getIdents:GetIdents<'t>) argsAreParameters (pattern:SynPat) =
314+
let rec getPatternIdents<'t> (accessibility:AccessControlLevel) (getIdents:GetIdents<'t>) argsAreParameters (pattern:SynPat) =
310315
match pattern with
311316
| SynPat.LongIdent(_, _, _, args, access, _) ->
312317
let identAccessibility = checkAccessibility accessibility access
@@ -321,11 +326,11 @@ let rec getPatternIdents<'t> (accessibility:Accessibility) (getIdents:GetIdents<
321326
| SynArgPats.NamePatPairs(pats, _) ->
322327
pats
323328
|> List.toArray
324-
|> Array.collect (snd >> getPatternIdents Accessibility.Private getIdents false)
329+
|> Array.collect (snd >> getPatternIdents AccessControlLevel.Private getIdents false)
325330
| SynArgPats.Pats(pats) ->
326331
pats
327332
|> List.toArray
328-
|> Array.collect (getPatternIdents Accessibility.Private getIdents false)
333+
|> Array.collect (getPatternIdents AccessControlLevel.Private getIdents false)
329334

330335
// Only check if expecting args as parameters e.g. function - otherwise is a DU pattern.
331336
if hasNoArgs || argsAreParameters then

src/FSharpLint.Core/Rules/Conventions/Naming/ParameterNames.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ let private getIdentifiers (args:AstNodeRuleParams) =
4343
let accessibility = getAccessibility args.SyntaxArray args.NodeIndex
4444
getPatternIdents accessibility (getValueOrFunctionIdents args.CheckInfo) true pattern
4545
| Member | Property ->
46-
getPatternIdents Accessibility.Private getMemberIdents true pattern
46+
getPatternIdents AccessControlLevel.Private getMemberIdents true pattern
4747
| _ -> Array.empty
4848
else
4949
Array.empty
5050
| AstNode.Expression(SynExpr.ForEach(_, _, true, pattern, _, _, _)) ->
51-
getPatternIdents Accessibility.Private (getValueOrFunctionIdents args.CheckInfo) false pattern
51+
getPatternIdents AccessControlLevel.Private (getValueOrFunctionIdents args.CheckInfo) false pattern
5252
| _ -> Array.empty
5353

5454
let rule config =

src/FSharpLint.Core/Rules/Conventions/Naming/PrivateValuesNames.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let private getValueOrFunctionIdents typeChecker accessibility pattern =
2020
match List.tryLast longIdent.Lid with
2121
| Some ident when not (isActivePattern ident) && singleIdentifier ->
2222
let checkNotUnionCase = checkNotUnionCase ident
23-
if accessibility = Accessibility.Private then
23+
if accessibility = AccessControlLevel.Private then
2424
(ident, ident.idText, Some checkNotUnionCase)
2525
|> Array.singleton
2626
else
@@ -31,7 +31,7 @@ let private getValueOrFunctionIdents typeChecker accessibility pattern =
3131
let private getIdentifiers (args:AstNodeRuleParams) =
3232
match args.AstNode with
3333
| AstNode.Expression(SynExpr.ForEach(_, _, true, pattern, _, _, _)) ->
34-
getPatternIdents Accessibility.Private (getValueOrFunctionIdents args.CheckInfo) false pattern
34+
getPatternIdents AccessControlLevel.Private (getValueOrFunctionIdents args.CheckInfo) false pattern
3535
| AstNode.Binding(SynBinding(access, _, _, _, attributes, _, valData, pattern, _, _, _, _)) ->
3636
if not (isLiteral attributes) then
3737
match identifierTypeFromValData valData with

src/FSharpLint.Core/Rules/Conventions/Naming/PublicValuesNames.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let private getValueOrFunctionIdents typeChecker isPublic pattern =
2424
match List.tryLast longIdent.Lid with
2525
| Some ident when singleIdentifier ->
2626
let checkNotUnionCase = checkNotUnionCase ident
27-
if isPublic = Accessibility.Public && isNotActivePattern ident then
27+
if isPublic = AccessControlLevel.Public && isNotActivePattern ident then
2828
(ident, ident.idText, Some checkNotUnionCase)
2929
|> Array.singleton
3030
else
@@ -35,7 +35,7 @@ let private getValueOrFunctionIdents typeChecker isPublic pattern =
3535
let private getIdentifiers (args:AstNodeRuleParams) =
3636
match args.AstNode with
3737
| AstNode.Expression(SynExpr.ForEach(_, _, true, pattern, _, _, _)) ->
38-
getPatternIdents Accessibility.Private (getValueOrFunctionIdents args.CheckInfo) false pattern
38+
getPatternIdents AccessControlLevel.Private (getValueOrFunctionIdents args.CheckInfo) false pattern
3939
| AstNode.Binding(SynBinding(_, _, _, _, attributes, _, valData, pattern, _, _, _, _)) ->
4040
if not (isLiteral attributes || isExtern attributes) then
4141
match identifierTypeFromValData valData with

0 commit comments

Comments
 (0)