Slide 1

Slide 1 text

lintnet - General purpose linter powered by Jsonnet Shunsuke Suzuki 2024-06-07 Lint Night#3 1

Slide 2

Slide 2 text

Self introduction Shunsuke Suzuki Platform Engineer at Mercari Platform Group GitHub: suzuki-shunsuke X: szkdash 2

Slide 3

Slide 3 text

My OSS ● aqua - Declarative CLI Version Manager written in Go ● tfcmt - Notify the result of terraform to GitHub pull requests ● tfaction - GitHub Actions for Terraform Monorepo ● etc 3

Slide 4

Slide 4 text

Overview ● Introduction of my new OSS lintnet ● What’s lintnet? 4

Slide 5

Slide 5 text

What’s lintnet? ● https://lintnet.github.io/ ● General purpose linter for structured configuration data powered by Jsonnet ● CLI like Conftest ● Single binary written in Go. No dependency and easy to install ● lintnet itself has no lint rule. You can define lint rules and lint files 5

Slide 6

Slide 6 text

General purpose ● k8s, Terraform, GitHub Actions, CircleCI, etc ● No need to use different linters and develop linters from scratch ● Support various data format ● Programing languages aren't supported 6

Slide 7

Slide 7 text

Jsonnet ● Superset of JSON for dynamic configuration ● Generate JSON dynamically https://jsonnet.org/ 7

Slide 8

Slide 8 text

Jsonnet ● Popular ● Simple - low learning cost ● Powerful - if, for, function, std lib, import, native function, etc ● Secure - restrict access to filesystem and network and OS command 8

Slide 9

Slide 9 text

Extend Jsonnet by Native functions ● lintnet extends Jsonnet by adding native functions ● https://lintnet.github.io/docs/lint-rule/native-function/ 9

Slide 10

Slide 10 text

Module ● Easy to reuse and distribute lint rules ● Reuse is just referring to modules in config or lint files ● Distribution is just publishing Jsonnet files in GitHub repositories ● Hopefully many awesome modules are published by community so that we can achieve awesome lint easily 10

Slide 11

Slide 11 text

Auto module update by Renovate ● https://github.com/lintnet/renovate-config ● lintnet’s Official Renovate Preset 11

Slide 12

Slide 12 text

Official Modules ● Official Modules ● e.g. ○ lintnet-modules/ghalint - Port of ghalint ○ lintnet-modules/nllint - Port of nllint 12

Slide 13

Slide 13 text

Extra features ● Test lint rules ● Parameterize lint rules ● Lint across multiple files ● Customize Output ● Control the result by error level 13

Slide 14

Slide 14 text

How to achieve lint by Jsonnet 14

Slide 15

Slide 15 text

Limitation ● Utilize the location of lint errors ○ reviewdog and editor integration ○ Output code where error occurs ● Auto fix ● Disable some lint rules by code annotation ● Lint of programming languages It's difficult to support them as a general purpose linter 15

Slide 16

Slide 16 text

How to use lintnet 1. Create a configuration file lintnet.jsonnet 2. Define lint rules by Jsonnet 3. Test rules by Jsonnet 4. Run lintnet lint command 16

Slide 17

Slide 17 text

Configuration file (lintnet.jsonnet) $ lintnet init 17

Slide 18

Slide 18 text

Lint rule hello.jsonnet 18

Slide 19

Slide 19 text

Test hello_test.jsonnet *_test.jsonnet A list of test cases test data + expected lint result $ lintnet test 19

Slide 20

Slide 20 text

Run lintnet 20

Slide 21

Slide 21 text

Comparison with Conftest 21

Slide 22

Slide 22 text

Conftest ● https://www.conftest.dev/ ● Utility to help you write tests against structured configuration data ● Use Rego as a Policy Language ● Cover various lint rules with one tool 22

Slide 23

Slide 23 text

Issues of Conftest ● Low reusability of policies ○ People develop similar lint rules independently ○ No standard way to share policies across multiple repositories ○ conftest push/pull is a low level API ○ https://www.conftest.dev/sharing/ 23

Slide 24

Slide 24 text

Compared with Conftest ● Easy to reuse and distribute lint rules by Module ● Standardized workflow by Configuration file and sub commands 24

Slide 25

Slide 25 text

Jsonnet vs Rego ● It is difficult to compare them objectively ● This is up to users ● Some people feel Rego is difficult and Jsonnet is easier than Rego 25

Slide 26

Slide 26 text

Summary ● lintnet is a general purpose linter powered by Jsonnet ● Users don’t need to use many different linters ● Developers can focus on developing lint rules ● lintnet enables us to reuse and distribute lint rules by Module 26