Skip to content

Commit a3d60f1

Browse files
committed
narrow synchronized region in pyflakes rule
1 parent f09672e commit a3d60f1

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

rule_pyflakes.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ func (rule *RulePyflakes) runPyflakes(src string, pos *Pos) {
126126
return nil
127127
}
128128

129-
rule.mu.Lock()
130-
defer rule.mu.Unlock()
131129
for len(stdout) > 0 {
132130
if stdout, err = rule.parseNextError(stdout, pos); err != nil {
133131
return err
@@ -157,7 +155,11 @@ func (rule *RulePyflakes) parseNextError(stdout []byte, pos *Pos) ([]byte, error
157155
} else {
158156
return nil, fmt.Errorf("error message from pyflakes does not end with \\n nor \\r\\n while checking script at %s. output: %q", pos, stdout)
159157
}
158+
159+
// This method needs to be thread-safe since concurrentProcess.run calls its callback in a different goroutine.
160+
rule.mu.Lock()
160161
rule.Errorf(pos, "pyflakes reported issue in this script: %s", msg)
162+
rule.mu.Unlock()
161163

162164
return b, nil
163165
}

rule_pyflakes_test.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,36 @@ func TestRulePyflakesDetectPythonShell(t *testing.T) {
1313
step string // Shell name set at 'shell' in Step node
1414
}{
1515
{
16-
what: "no default shell",
16+
what: "no default shell",
1717
isPython: false,
1818
},
1919
{
20-
what: "workflow default",
20+
what: "workflow default",
2121
isPython: true,
2222
workflow: "python",
2323
},
2424
{
25-
what: "job default",
25+
what: "job default",
2626
isPython: true,
27-
job: "python",
27+
job: "python",
2828
},
2929
{
30-
what: "step shell",
30+
what: "step shell",
3131
isPython: true,
32-
step: "python",
32+
step: "python",
3333
},
3434
{
35-
what: "custom shell",
35+
what: "custom shell",
3636
isPython: true,
3737
workflow: "python {0}",
3838
},
3939
{
40-
what: "other shell",
40+
what: "other shell",
4141
isPython: false,
4242
workflow: "pwsh",
4343
},
4444
{
45-
what: "other custom shell",
45+
what: "other custom shell",
4646
isPython: false,
4747
workflow: "bash -e {0}",
4848
},

testdata/ok/shellcheck_step_shell.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ jobs:
1313
# This causes SC1001 if `shell:` is not set explicitly
1414
- run: cat xxx\yyy.txt
1515
if: ${{ matrix.os == 'windows-latest' }}
16-
shell: 'python {0}'
16+
shell: 'pwsh {0}'

0 commit comments

Comments
 (0)