Skip to content

Commit

Permalink
add working-directory configuration (#8)
Browse files Browse the repository at this point in the history
* update vscode settings

* add working-directory arg

* make cwd absolute

* convert all paths to absolute
  • Loading branch information
a-b-r-o-w-n authored Jan 17, 2020
1 parent 53fa3da commit ae16537
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
8 changes: 5 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"git.ignoreLimitWarning": true,
"eslint.enable": true,
"eslint.autoFixOnSave": true,
"eslint.validate": [
"javascript",
"javascriptreact",
{ "language": "typescript", "autoFix": true },
{ "language": "typescriptreact", "autoFix": true }
"typescript",
"typescriptreact"
],
"typescript.tsdk": "node_modules/typescript/lib",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
}
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ inputs:
ignore:
description: "Glob pattern to ignore from linting."
default: "**/node_modules/**"
working-directory:
description: "Directory where eslint should execute."
runs:
using: "node12"
main: "lib/eslint-action.js"
Expand Down
16 changes: 13 additions & 3 deletions lib/eslint-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable @typescript-eslint/camelcase */
const path_1 = __importDefault(require("path"));
const core = __importStar(require("@actions/core"));
const github = __importStar(require("@actions/github"));
const eslint_1 = __importDefault(require("eslint"));
Expand Down Expand Up @@ -51,9 +52,18 @@ const processArrayInput = (key, required = false) => {
function lint(files) {
const extensions = processArrayInput('extensions', true);
const ignoreGlob = processArrayInput('ignore');
let cwd = core.getInput('working-directory');
if (cwd && !path_1.default.isAbsolute(cwd)) {
cwd = path_1.default.resolve(cwd);
}
else if (!cwd) {
cwd = process.cwd();
}
core.debug(`Starting lint engine with cwd: ${cwd}`);
const linter = new eslint_1.default.CLIEngine({
extensions,
ignorePattern: ignoreGlob,
cwd,
});
return linter.executeOnFiles(files);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/fileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports.filterFiles = (files, globs) => {
const filtered = micromatch_1.default(files, globs);
for (const file of filtered) {
if (fs_1.default.existsSync(path_1.default.resolve(file))) {
result.push(file);
result.push(path_1.default.resolve(file));
}
}
return result;
Expand Down
12 changes: 12 additions & 0 deletions src/eslint-action.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable @typescript-eslint/camelcase */
import path from 'path';

import * as core from '@actions/core';
import * as github from '@actions/github';
import eslint, { CLIEngine } from 'eslint';
Expand Down Expand Up @@ -41,10 +43,20 @@ const processArrayInput = (key: string, required = false): string[] => {
function lint(files: string[]): CLIEngine.LintReport {
const extensions = processArrayInput('extensions', true);
const ignoreGlob = processArrayInput('ignore');
let cwd = core.getInput('working-directory');

if (cwd && !path.isAbsolute(cwd)) {
cwd = path.resolve(cwd);
} else if (!cwd) {
cwd = process.cwd();
}

core.debug(`Starting lint engine with cwd: ${cwd}`);

const linter = new eslint.CLIEngine({
extensions,
ignorePattern: ignoreGlob,
cwd,
});

return linter.executeOnFiles(files);
Expand Down
2 changes: 1 addition & 1 deletion src/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const filterFiles = (files: string[], globs: string[]): string[] => {

for (const file of filtered) {
if (fs.existsSync(path.resolve(file))) {
result.push(file);
result.push(path.resolve(file));
}
}

Expand Down

0 comments on commit ae16537

Please sign in to comment.