Skip to content

Commit 9bd97c7

Browse files
committed
chore: add pre-commit
Signed-off-by: Felipe Zipitria <felipe.zipitria@owasp.org>
1 parent daa5805 commit 9bd97c7

48 files changed

Lines changed: 78 additions & 58 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
go-version: '1.23'
3535

3636
- name: Build
37-
run: |
37+
run: |
3838
go run mage.go generate
3939
4040
- name: Test

.github/workflows/python.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,3 @@ jobs:
6060
- name: "Run unit tests"
6161
run: |
6262
uv run pytest -vs
63-

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ go.work.sum
7474

7575
# Editor/IDE
7676
.idea/
77-
.vscode/
77+
.vscode/

.pre-commit-config.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
ci:
3+
autofix_commit_msg: |
4+
chore(formatting): auto fixes from pre-commit hooks
5+
6+
for more information, see https://pre-commit.ci
7+
autofix_prs: true
8+
skip: []
9+
submodules: false
10+
# Update the rev variable with the release version that you want, from the yamllint repo
11+
# You can pass your custom .yamllint with args attribute.
12+
repos:
13+
- repo: https://github.com/pre-commit/pre-commit-hooks
14+
rev: v5.0.0
15+
hooks:
16+
- id: check-yaml
17+
args: [--allow-multiple-documents]
18+
- id: end-of-file-fixer
19+
- id: trailing-whitespace
20+
exclude: '^regex-assembly/'
21+
args: [--markdown-linebreak-ext=md]
22+
- repo: local
23+
hooks:
24+
- id: run-generate
25+
name: run-generate
26+
entry: './generate.sh'
27+
language: script
28+
pass_filenames: false
29+
files: '^g4/'

README.md

Lines changed: 1 addition & 1 deletion

g4/SecLangLexer.g4

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ tokens {
2323
}
2424

2525
WS
26-
: ([ \t\r\n]+ | '\\' '\n' | '\\') -> skip
26+
: ([ \t\r\n]+ | '\\' '\n' | '\\') -> skip
2727
;
2828

2929
COMMENT
@@ -117,8 +117,8 @@ RPAREN
117117
// MODSEC CONFIG
118118
ACTION_ACCURACY
119119
: 'accuracy'
120-
;
121-
120+
;
121+
122122
ACTION_ALLOW
123123
: 'allow:' ('REQUEST'|'PHASE') | ('phase:' ('REQUEST|PHASE') | 'allow')
124124
;
@@ -1256,11 +1256,11 @@ SPACE_COL
12561256
: ' ' -> skip, pushMode(OPERATOR_START_MODE)
12571257
;
12581258
1259-
COMMA_COL
1259+
COMMA_COL
12601260
: ',' -> type(COMMA), popMode
12611261
;
12621262
1263-
QUOTE_COL
1263+
QUOTE_COL
12641264
: '"' -> type(QUOTE), popMode
12651265
;
12661266
@@ -1274,11 +1274,11 @@ SPACE_VAR
12741274
: ' ' -> skip, pushMode(OPERATOR_START_MODE)
12751275
;
12761276
1277-
COMMA_VAR
1277+
COMMA_VAR
12781278
: ',' -> type(COMMA), popMode
12791279
;
12801280
1281-
QUOTE_VAR
1281+
QUOTE_VAR
12821282
: '"' -> type(QUOTE), popMode
12831283
;
12841284
@@ -1323,10 +1323,10 @@ NOT_OPERATOR
13231323
;
13241324
13251325
SKIP_CHARS
1326-
: [\\\t\r\n ]+ -> skip
1326+
: [\\\t\r\n ]+ -> skip
13271327
;
13281328
1329-
QUOTE_OP
1329+
QUOTE_OP
13301330
: '"' -> type(QUOTE), pushMode(OPERATOR_WITH_QUOTES)
13311331
;
13321332
@@ -1347,4 +1347,3 @@ AT
13471347
OPERATOR_QUOTED_STRING
13481348
: (('\\"') | ~([" @!])) (('\\"')|~('"'))* -> pushMode(DEFAULT_MODE)
13491349
;
1350-

g4/SecLangParser.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,4 +487,4 @@ assignment:
487487
EQUAL
488488
| EQUALS_PLUS
489489
| EQUALS_MINUS
490-
;
490+
;

g4/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
package g4
55

6-
//go:generate ./generate.sh
6+
//go:generate ../generate.sh

g4/generate.sh renamed to generate.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
# Copyright 2023 Felipe Zipitria
33
# SPDX-License-Identifier: Apache-2.0
44

5+
# This script is used to generate the parser files for the seclang DSL.
6+
# It is used by the pre-commit hook to ensure that the parser files are up to date.
7+
8+
# Check if java is installed
9+
if ! command -v java >/dev/null 2>&1; then
10+
echo "Java is not installed. Please install Java and try again."
11+
exit 1
12+
fi
13+
14+
cd g4
515

616
alias antlr4='java -Xmx500M -cp "../lib/antlr-4.13.2-complete.jar:$CLASSPATH" org.antlr.v4.Tool'
717
antlr4 -Dlanguage=Go -no-visitor -package parser -o ../parser *.g4

parser/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)