Skip to content

Commit ae16537

Browse files
authored
add working-directory configuration (#8)
* update vscode settings * add working-directory arg * make cwd absolute * convert all paths to absolute
1 parent 53fa3da commit ae16537

File tree

6 files changed

+34
-8
lines changed

6 files changed

+34
-8
lines changed

.vscode/settings.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
{
22
"git.ignoreLimitWarning": true,
33
"eslint.enable": true,
4-
"eslint.autoFixOnSave": true,
54
"eslint.validate": [
65
"javascript",
76
"javascriptreact",
8-
{ "language": "typescript", "autoFix": true },
9-
{ "language": "typescriptreact", "autoFix": true }
7+
"typescript",
8+
"typescriptreact"
109
],
1110
"typescript.tsdk": "node_modules/typescript/lib",
11+
"editor.codeActionsOnSave": {
12+
"source.fixAll.eslint": true
13+
},
1214
}

action.yml

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ inputs:
1313
ignore:
1414
description: "Glob pattern to ignore from linting."
1515
default: "**/node_modules/**"
16+
working-directory:
17+
description: "Directory where eslint should execute."
1618
runs:
1719
using: "node12"
1820
main: "lib/eslint-action.js"

lib/eslint-action.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
88
step((generator = generator.apply(thisArg, _arguments || [])).next());
99
});
1010
};
11+
var __importDefault = (this && this.__importDefault) || function (mod) {
12+
return (mod && mod.__esModule) ? mod : { "default": mod };
13+
};
1114
var __importStar = (this && this.__importStar) || function (mod) {
1215
if (mod && mod.__esModule) return mod;
1316
var result = {};
1417
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
1518
result["default"] = mod;
1619
return result;
1720
};
18-
var __importDefault = (this && this.__importDefault) || function (mod) {
19-
return (mod && mod.__esModule) ? mod : { "default": mod };
20-
};
2121
Object.defineProperty(exports, "__esModule", { value: true });
2222
/* eslint-disable @typescript-eslint/camelcase */
23+
const path_1 = __importDefault(require("path"));
2324
const core = __importStar(require("@actions/core"));
2425
const github = __importStar(require("@actions/github"));
2526
const eslint_1 = __importDefault(require("eslint"));
@@ -51,9 +52,18 @@ const processArrayInput = (key, required = false) => {
5152
function lint(files) {
5253
const extensions = processArrayInput('extensions', true);
5354
const ignoreGlob = processArrayInput('ignore');
55+
let cwd = core.getInput('working-directory');
56+
if (cwd && !path_1.default.isAbsolute(cwd)) {
57+
cwd = path_1.default.resolve(cwd);
58+
}
59+
else if (!cwd) {
60+
cwd = process.cwd();
61+
}
62+
core.debug(`Starting lint engine with cwd: ${cwd}`);
5463
const linter = new eslint_1.default.CLIEngine({
5564
extensions,
5665
ignorePattern: ignoreGlob,
66+
cwd,
5767
});
5868
return linter.executeOnFiles(files);
5969
}

lib/fileUtils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ exports.filterFiles = (files, globs) => {
2929
const filtered = micromatch_1.default(files, globs);
3030
for (const file of filtered) {
3131
if (fs_1.default.existsSync(path_1.default.resolve(file))) {
32-
result.push(file);
32+
result.push(path_1.default.resolve(file));
3333
}
3434
}
3535
return result;

src/eslint-action.ts

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/* eslint-disable @typescript-eslint/camelcase */
2+
import path from 'path';
3+
24
import * as core from '@actions/core';
35
import * as github from '@actions/github';
46
import eslint, { CLIEngine } from 'eslint';
@@ -41,10 +43,20 @@ const processArrayInput = (key: string, required = false): string[] => {
4143
function lint(files: string[]): CLIEngine.LintReport {
4244
const extensions = processArrayInput('extensions', true);
4345
const ignoreGlob = processArrayInput('ignore');
46+
let cwd = core.getInput('working-directory');
47+
48+
if (cwd && !path.isAbsolute(cwd)) {
49+
cwd = path.resolve(cwd);
50+
} else if (!cwd) {
51+
cwd = process.cwd();
52+
}
53+
54+
core.debug(`Starting lint engine with cwd: ${cwd}`);
4455

4556
const linter = new eslint.CLIEngine({
4657
extensions,
4758
ignorePattern: ignoreGlob,
59+
cwd,
4860
});
4961

5062
return linter.executeOnFiles(files);

src/fileUtils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const filterFiles = (files: string[], globs: string[]): string[] => {
1313

1414
for (const file of filtered) {
1515
if (fs.existsSync(path.resolve(file))) {
16-
result.push(file);
16+
result.push(path.resolve(file));
1717
}
1818
}
1919

0 commit comments

Comments
 (0)