This repository was archived by the owner on Aug 25, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed
Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818 - Static file serving from a dirctory with ` -static `
1919 - ` api.js ` file serving with the ` -js ` flag
2020 - Docs page for JavaScript example
21+ - shouldi got an operation to run golangci-lint on Golang code
2122### Fixed
2223- Port assignment for the HTTP API via the ` -port ` flag
2324### Changed
Original file line number Diff line number Diff line change 1+ import json
2+ import asyncio
3+ from typing import Dict , Any
4+
5+ from dffml .df .base import op
6+ from dffml .df .types import Definition
7+
8+ package_src_dir = Definition (name = "package_src_dir" , primitive = "str" )
9+ golangci_lint_output = Definition (
10+ name = "golangci_lint_output" , primitive = "Dict[str, Any]"
11+ )
12+
13+
14+ @op (inputs = {"pkg" : package_src_dir }, outputs = {"report" : golangci_lint_output })
15+ async def run_golangci_lint (pkg : str ) -> Dict [str , Any ]:
16+ """
17+ CLI usage: dffml service dev run -log debug shouldi.golangci_lint:run_golangci_lint -pkg .
18+ """
19+ proc = await asyncio .create_subprocess_exec (
20+ "golangci-lint" ,
21+ "run" ,
22+ "--out-format" ,
23+ "json" ,
24+ pkg ,
25+ stdout = asyncio .subprocess .PIPE ,
26+ stderr = asyncio .subprocess .PIPE ,
27+ )
28+ stdout , _stderr = await proc .communicate ()
29+ if len (stdout ) == 0 :
30+ raise Exception (_stderr )
31+
32+ golangci_lint_op = stdout .decode ()
33+ issues = json .loads (golangci_lint_op )
34+
35+ return {"issues" : len (issues ["Issues" ])}
Original file line number Diff line number Diff line change 1+ import os
2+
3+ from dffml .util .asynctestcase import AsyncTestCase
4+
5+ from shouldi .golangci_lint import run_golangci_lint
6+
7+
8+ class TestRunGolangci_lintOp (AsyncTestCase ):
9+ async def test_run (self ):
10+ results = await run_golangci_lint (os .getcwd ())
11+ self .assertEqual (type (results ["issues" ]), int )
You can’t perform that action at this time.
0 commit comments