Skip to content

Commit

Permalink
Don't complain about naming of extern functions (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt authored Jul 5, 2021
1 parent a97b032 commit 0bc3694
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.19.2] - 2021-07-05

- Fix for extern function naming #487
- Doc update - configuration file info.

## [0.19.1] - 2021-06-23
Expand Down
2 changes: 2 additions & 0 deletions src/FSharpLint.Core/Rules/Conventions/Naming/NamingHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ let isAttribute name (attributes:SynAttributes) =

let isLiteral = isAttribute "Literal"

let isExtern = isAttribute "DllImport"

let isMeasureType = isAttribute "Measure"

let isNotUnionCase (checkFile:FSharpCheckFileResults) (ident:Ident) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ let private getIdentifiers (args:AstNodeRuleParams) =
match args.AstNode with
| AstNode.Expression(SynExpr.ForEach(_, _, true, pattern, _, _, _)) ->
getPatternIdents false (getValueOrFunctionIdents args.CheckInfo) false pattern
| AstNode.Binding(SynBinding(access, _, _, _, attributes, _, valData, pattern, _, _, _, _)) ->
if not (isLiteral attributes) then
| AstNode.Binding(SynBinding(_, _, _, _, attributes, _, valData, pattern, _, _, _, _)) ->
if not (isLiteral attributes || isExtern attributes) then
match identifierTypeFromValData valData with
| Value | Function ->
let isPublic = isPublic args.SyntaxArray args.NodeIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ module Program
let (Cat, _) = 1, 0"""

this.AssertNoWarnings()

/// Extern functions typically match the counterpart from the external library
/// and as such often won't follow F#'s conventions.
[<Test>]
member this.``extern function definition should not trigger naming warnings``() =
this.Parse """
module Program
open System
open System.Runtime.InteropServices
[<DllImport(@"python37", EntryPoint = "PyThreadState_SetAsyncExc", CallingConvention = CallingConvention.Cdecl)>]
extern int PyThreadState_SetAsyncExcLLP64(uint id, IntPtr exc)
"""

this.AssertNoWarnings()

[<Test>]
member this.PublicTupleIsCamelCase() =
Expand Down

0 comments on commit 0bc3694

Please sign in to comment.