Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

annotate files relative to git root, instead of cwd, so that it works in nested packages in monorepos (+fix lint) #114

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"rules": {
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/camelcase": 0,
"camelcase": 0,
"complexity": 0,
"import/extensions": 0
}
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@
},
"dependencies": {
"create-check": "^0.6.0",
"eslint-formatter-pretty": "^3.0.0"
"eslint-formatter-pretty": "^3.0.0",
"execa": "^1.0.0"
},
"devDependencies": {
"@types/execa": "^0.9.0",
"@types/env-ci": "3.1.0",
"@types/eslint": "6.8.0",
"@types/lru-cache": "5.1.0",
"@typescript-eslint/eslint-plugin": "2.32.0",
"@typescript-eslint/parser": "2.32.0",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0",
"auto": "^10.43.0",
"auto-config-hipstersmoothie": "^4.0.0",
"eslint": "7.0.0",
"eslint": "^7.1.0",
"eslint-config-airbnb": "18.1.0",
"eslint-config-airbnb-base": "14.1.0",
"eslint-config-prettier": "6.11.0",
Expand Down
9 changes: 6 additions & 3 deletions src/create-check.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import createCheck, { Annotation } from 'create-check';
import path from 'path';
import eslint from 'eslint';
import execa from 'execa';

const APP_ID = 38817;
/**
Expand Down Expand Up @@ -45,7 +46,9 @@ rxXIyGcdFUjpY/U2tobjXousbYyz8/DqgDoLWXOMt2dNkbbNAN8L3OMVTGb6TzS2
gd8URXIGc6Nk7ueWMKEZaropIg6q1J7e9qJdlzA6j1fu6vVY3qX3tA==
-----END RSA PRIVATE KEY-----`;

export function createAnnotations(results: eslint.CLIEngine.LintResult[]) {
export async function createAnnotations(results: eslint.CLIEngine.LintResult[]) {
const repoRoot = (await execa('git', ['rev-parse', '--show-toplevel'])).stdout;

const annotations: Annotation[] = [];
const levels: Annotation['annotation_level'][] = [
'notice',
Expand All @@ -61,7 +64,7 @@ export function createAnnotations(results: eslint.CLIEngine.LintResult[]) {
const annotationLevel = levels[severity];

annotations.push({
path: path.relative(process.cwd(), filePath),
path: path.relative(repoRoot, filePath),
start_line: line,
end_line: line,
annotation_level: annotationLevel,
Expand Down Expand Up @@ -91,7 +94,7 @@ export default async (results: eslint.CLIEngine.LintResult[]) => {
return createCheck({
tool: 'ESLint',
name: process.env.GH_CHECK_NAME || 'Check Code for Errors',
annotations: createAnnotations(results),
annotations: await createAnnotations(results),
errorCount,
warningCount,
appId: process.env.ESLINT_APP_ID
Expand Down