Skip to content

Commit

Permalink
Add lint_goto_identifier option
Browse files Browse the repository at this point in the history
Fixes #108
  • Loading branch information
FPtje committed Jul 25, 2021
1 parent f4addb4 commit aac4cde
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Example `glualint.json` with the default options:
"lint_emptyBlocks": true,
"lint_shadowing": true,
"lint_gotos": true,
"lint_goto_identifier": true,
"lint_doubleNegations": true,
"lint_redundantIfStatements": true,
"lint_redundantParentheses": true,
Expand Down Expand Up @@ -84,6 +85,7 @@ Example `glualint.json` with the default options:
- `lint_emptyBlocks`: Warn for empty blocks
- `lint_shadowing`: Warn for variable shadowing
- `lint_gotos`: Warn for inappropriate gotos (i.e. the ones not used to jump out of a double loop)
- `lint_goto_identifier`: Warn when `goto` is used as an identifer (e.g. `a = {goto = 1}`). This warning exists because `goto` being allowed as identifier is actually a bug. You should not be able to use `goto` like that for the same reason you're not allowed to use any other keyword as identifier.
- `lint_doubleNegations`: Warn for double negations (things like `not (a == b)`)
- `lint_duplicateTableKeys`: Warn for duplicate table keys (e.g. `{a = 1, a = 2}`)
- `lint_profanity`: Warn for profanity (bitch, cock, cocks, cunt, dick, dicks, fuck, fucking, goddamnit, knob, knobs, motherfucker, nigger, niggers, niggertits, nipple, shit)
Expand Down
11 changes: 3 additions & 8 deletions src/GLuaFixer/AG/ASTLint.ag
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,14 @@ unknownIdentifier = "Unknown identifier"
----------------------------------------

attr AllStuff
inh config :: LintSettings

inh scopeLevel :: Int
inh loopLevel :: Int -- In how many scopes of loops we are. Used in checking labels

-- The style of variables, used for warning about inconsistencies
chn variableStyle :: DeterminedVariableStyle

attr AllStuff MToken MTokenList
inh config :: LintSettings
chn mtokenPos :: {Region} -- The location of the warning

-- Global variable definitions
Expand All @@ -156,9 +155,6 @@ attr AllStuff MToken MTokenList Token TokenList Region
syn copy :: self
syn identifier use {const} {unknownIdentifier} :: String -- identifier of the first token

attr Token TokenList
syn tokenWarnings use {++} {[]} :: {[String]}

attr Block MStat MStatList AReturn MElse
syn statementCount use {+} {1} :: Int

Expand Down Expand Up @@ -226,15 +222,14 @@ sem Token
lhs.identifier = @lbl
| Identifier
lhs.identifier = @ident
+tokenWarnings = if @ident /= "goto" then id else
(:) "Don't use 'goto' as an identifier, later versions of Lua will confuse it with the goto keyword."

sem MToken
| MToken
lhs.mtokenPos = @mpos.copy
lhs.mtok = @mtok.copy
lhs.warnings = map (warn @mpos.copy) @mtok.tokenWarnings
lhs.identifier = @mtok.identifier
+warnings = if not (lint_goto_identifier @lhs.config) || @mtok.identifier /= "goto" then id else
(:) $ warn @mpos.copy "Don't use 'goto' as an identifier, later versions of Lua will confuse it with the goto keyword."

sem MTokenList MStatList MExprList FieldList VarsList
| Cons
Expand Down
4 changes: 4 additions & 0 deletions src/GLuaFixer/LintSettings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ data LintSettings =
, lint_emptyBlocks :: !Bool
, lint_shadowing :: !Bool
, lint_gotos :: !Bool
, lint_goto_identifier :: !Bool
, lint_doubleNegations :: !Bool
, lint_redundantIfStatements :: !Bool
, lint_redundantParentheses :: !Bool
Expand Down Expand Up @@ -58,6 +59,7 @@ defaultLintSettings =
, lint_emptyBlocks = True
, lint_shadowing = True
, lint_gotos = True
, lint_goto_identifier = True
, lint_doubleNegations = True
, lint_redundantIfStatements = True
, lint_redundantParentheses = True
Expand Down Expand Up @@ -98,6 +100,7 @@ instance FromJSON LintSettings where
v .:? "lint_emptyBlocks" .!= lint_emptyBlocks defaultLintSettings <*>
v .:? "lint_shadowing" .!= lint_shadowing defaultLintSettings <*>
v .:? "lint_gotos" .!= lint_gotos defaultLintSettings <*>
v .:? "lint_goto_identifier" .!= lint_goto_identifier defaultLintSettings <*>
v .:? "lint_doubleNegations" .!= lint_doubleNegations defaultLintSettings <*>
v .:? "lint_redundantIfStatements" .!= lint_redundantIfStatements defaultLintSettings <*>
v .:? "lint_redundantParentheses" .!= lint_redundantParentheses defaultLintSettings <*>
Expand Down Expand Up @@ -152,6 +155,7 @@ instance ToJSON LintSettings where
, "lint_emptyBlocks" .= lint_emptyBlocks ls
, "lint_shadowing" .= lint_shadowing ls
, "lint_gotos" .= lint_gotos ls
, "lint_goto_identifier" .= lint_goto_identifier ls
, "lint_doubleNegations" .= lint_doubleNegations ls
, "lint_redundantIfStatements" .= lint_redundantIfStatements ls
, "lint_redundantParentheses" .= lint_redundantParentheses ls
Expand Down

0 comments on commit aac4cde

Please sign in to comment.