Skip to content

Commit eddfd29

Browse files
committed
lint code
1 parent f0d186d commit eddfd29

5 files changed

Lines changed: 28 additions & 20 deletions

File tree

cjpm.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
cjc-version = "1.0.0"
33
name = "cenum"
44
description = "C enum macro"
5-
version = "1.1.0"
5+
version = "1.1.1"
66
target-dir = ""
77
src-dir = ""
88
output-type = "dynamic"

src/common.cj

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
macro package cenum
22

3-
import std.ast.*
4-
import std.convert.*
5-
import std.math.*
3+
import std.ast.{diagReport, DiagReportLevel, Token, TokenKind, Tokens, ToTokens}
4+
import std.convert.Parsable
5+
import std.math.abs
6+
7+
// cjlint-ignore -start !G.FUN.01 function should be less than 50 lines of code
68

79
private func enumBlockBegin(visibility: Token, name: Token, valueType: Token, addFlagOps!: Bool, ffi_c!: Bool): Tokens {
810
let block = quote()
@@ -93,10 +95,6 @@ private func enumBlockBegin(visibility: Token, name: Token, valueType: Token, ad
9395
return block
9496
}
9597

96-
private let enumBlockEnd: Tokens = quote(
97-
}
98-
)
99-
10098
private func parseEnumValue(currentEnumIndex: Int32, tokenIt: Iterator<Token>): (Tokens, Int32) {
10199
let valueTokens = quote()
102100
var hasAssign = false
@@ -128,8 +126,8 @@ private func parseEnumValue(currentEnumIndex: Int32, tokenIt: Iterator<Token>):
128126
return (quote(), currentEnumIndex)
129127
}
130128

131-
const errorMsg = "Invalid CEnum syntax"
132-
const errorHint = "Syntax: CEnum[<Private|public|..> <Identifier> <type>]()\n" +
129+
private const ERROR_MSG = "Invalid CEnum syntax"
130+
private const ERROR_HINT = "Syntax: CEnum[<Private|public|..> <Identifier> <type>]()\n" +
133131
"Example: CEnum[Seek](...), CEnum[public Seek](...), CEnum[public Seek UInt32](...)"
134132

135133
func makeEnum(attrTokens: Tokens, inputTokens: Tokens, flagEnum!: Bool = false, startValue!: Int32 = 0,
@@ -152,20 +150,20 @@ func makeEnum(attrTokens: Tokens, inputTokens: Tokens, flagEnum!: Bool = false,
152150
visibility = attrTokens[0]
153151
name = attrTokens[1]
154152
valueType = attrTokens[2]
155-
case _ => diagReport(DiagReportLevel.ERROR, attrTokens, errorMsg, errorHint)
153+
case _ => diagReport(DiagReportLevel.ERROR, attrTokens, ERROR_MSG, ERROR_HINT)
156154
}
157155

158156
if (visibility.kind != PRIVATE && visibility.kind != PROTECTED && visibility.kind != INTERNAL && visibility.kind !=
159157
PUBLIC) {
160-
diagReport(DiagReportLevel.ERROR, attrTokens, errorMsg, errorHint)
158+
diagReport(DiagReportLevel.ERROR, attrTokens, ERROR_MSG, ERROR_HINT)
161159
}
162160
if (name.kind != IDENTIFIER) {
163-
diagReport(DiagReportLevel.ERROR, attrTokens, errorMsg, errorHint)
161+
diagReport(DiagReportLevel.ERROR, attrTokens, ERROR_MSG, ERROR_HINT)
164162
}
165163
if (valueType.kind != INT8 && valueType.kind != INT16 && valueType.kind != INT32 && valueType.kind != INT64 &&
166164
valueType.kind != UINT8 && valueType.kind != UINT16 && valueType.kind != UINT32 && valueType.kind != UINT64 &&
167165
valueType.kind != INTNATIVE && valueType.kind != UINTNATIVE) {
168-
diagReport(DiagReportLevel.ERROR, attrTokens, errorMsg, errorHint)
166+
diagReport(DiagReportLevel.ERROR, attrTokens, ERROR_MSG, ERROR_HINT)
169167
}
170168

171169
var enumQuote = enumBlockBegin(visibility, name, valueType, addFlagOps: flagEnum, ffi_c: ffi_c)
@@ -196,6 +194,10 @@ func makeEnum(attrTokens: Tokens, inputTokens: Tokens, flagEnum!: Bool = false,
196194
index *= 2
197195
}
198196
}
199-
enumQuote.append(enumBlockEnd)
197+
enumQuote.append(quote(
198+
}
199+
))
200200
return enumQuote
201201
}
202+
203+
// cjlint-ignore -end function should be less than 50 lines of code

src/enums.cj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
macro package cenum
22

3-
import std.ast.*
3+
import std.ast.Tokens
44
55
public macro Enum(attrTokens: Tokens, inputTokens: Tokens) {
66
makeEnum(attrTokens, inputTokens)
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package cenum.test
22

3-
import cenum.*
4-
import std.unittest.*
3+
import cenum.Enum
4+
5+
// cjlint-ignore -start !G.NAM.04 function names should be lower camel case
56

67
@Enum[SimpleEnum](
78
Val1
@@ -66,3 +67,5 @@ func test_CustomValueEnum3_value() {
6667
@Expect(CustomValueEnum3.Val5.value, 8i64)
6768
@Expect(CustomValueEnum3.Val6.value, 9i64)
6869
}
70+
71+
// cjlint-ignore -end function names should be lower camel case
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package cenum.test
22

3-
import cenum.*
4-
import std.unittest.*
3+
import cenum.{FlagEnum, FlagEnum0, FlagEnum1}
4+
5+
// cjlint-ignore -start !G.NAM.04 function names should be lower camel case
56

67
@FlagEnum[SimpleFlagEnum](
78
Val1
@@ -216,3 +217,5 @@ func test_SimpleFlagEnum3_clear() {
216217
@Expect(flags.isSet(SimpleFlagEnum3.Val3) == false)
217218
@Expect(flags.isSet(SimpleFlagEnum3.Val4) == false)
218219
}
220+
221+
// cjlint-ignore -end function names should be lower camel case

0 commit comments

Comments
 (0)