Skip to content

Commit

Permalink
Add 'annotate' input, replacing 'no-comment'
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Feb 28, 2024
1 parent 328130c commit 93a05d0
Show file tree
Hide file tree
Showing 9 changed files with 1,649 additions and 88 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ inputs:
working-directory:
description: 'Directory to run pyright in. If not specified, the repo root will be used.'
required: false
no-comments:
description: 'Disable issue/commit comments.'
annotate:
description: 'A comma separated list of check annotations to emit. May be "none"/"false", "errors", "warnings", or "all"/"true" (shorthand for "errors, warnings").'
required: false
default: 'false'
default: 'all'

# Shorthand for pyright flags
create-stub:
Expand Down Expand Up @@ -93,6 +93,13 @@ inputs:
description: 'Use library code to infer types when stubs are missing.'
required: false
default: 'false'

# Deprecated
no-comments:
description: 'Disable issue/commit comments.'
required: false
default: 'false'
deprecationMessage: 'Use "annotate" instead.'
```
## Use with a virtualenv
Expand Down
13 changes: 10 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ inputs:
working-directory:
description: 'Directory to run pyright in. If not specified, the repo root will be used.'
required: false
no-comments:
description: 'Disable issue/commit comments.'
annotate:
description: 'A comma separated list of check annotations to emit. May be "none"/"false", "errors", "warnings", or "all"/"true" (shorthand for "errors, warnings").'
required: false
default: 'false'
default: 'all'

# Shorthand for pyright flags
create-stub:
Expand Down Expand Up @@ -80,6 +80,13 @@ inputs:
required: false
default: 'false'

# Deprecated
no-comments:
description: 'Disable issue/commit comments.'
required: false
default: 'false'
deprecationMessage: 'Use "annotate" instead.'

runs:
using: 'node20'
main: 'dist/index.js'
42 changes: 39 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9981,14 +9981,47 @@ async function getArgs() {
args.push(arg);
}
}
let annotateInput = core.getInput("annotate").trim() || "all";
if (isAnnotateNone(annotateInput)) {
annotateInput = "";
} else if (isAnnotateAll(annotateInput)) {
annotateInput = "errors, warnings";
}
const split = annotateInput ? annotateInput.split(",") : [];
const annotate = /* @__PURE__ */ new Set();
for (let value of split) {
value = value.trim();
switch (value) {
case "errors":
annotate.add("error");
break;
case "warnings":
annotate.add("warning");
break;
default:
if (isAnnotateAll(value) || isAnnotateNone(value)) {
throw new Error(`invalid value ${JSON.stringify(value)} in comma-separated annotate`);
}
throw new Error(`invalid value ${JSON.stringify(value)} for annotate`);
}
}
const noComments = getBooleanInput("no-comments", false) || args.some((arg) => flagsWithoutCommentingSupport.has(arg));
if (noComments) {
annotate.clear();
}
return {
workingDirectory,
noComments,
annotate,
pyrightVersion: pyrightInfo.version,
args
};
}
function isAnnotateNone(name) {
return name === "none" || name.toUpperCase() === "FALSE";
}
function isAnnotateAll(name) {
return name === "all" || name.toUpperCase() === "TRUE";
}
function getBooleanInput(name, defaultValue) {
const input = core.getInput(name);
if (!input) {
Expand Down Expand Up @@ -10054,15 +10087,15 @@ function printInfo(pyrightVersion, node, cwd, args) {
async function main() {
try {
const node = getNodeInfo(process);
const { workingDirectory, noComments, pyrightVersion, args } = await getArgs();
const { workingDirectory, annotate, pyrightVersion, args } = await getArgs();
if (workingDirectory) {
process.chdir(workingDirectory);
}
try {
checkOverriddenFlags(args);
} catch {
}
if (noComments) {
if (annotate.size === 0) {
printInfo(pyrightVersion, node, process.cwd(), args);
const { status: status2 } = cp.spawnSync(node.execPath, args, {
stdio: ["ignore", "inherit", "inherit"]
Expand Down Expand Up @@ -10097,6 +10130,9 @@ async function main() {
if (diag.severity === "information") {
continue;
}
if (!annotate.has(diag.severity)) {
continue;
}
const line = diag.range?.start.line ?? 0;
const col = diag.range?.start.character ?? 0;
const message = diagnosticToString(
Expand Down
Loading

0 comments on commit 93a05d0

Please sign in to comment.