Skip to content

Commit

Permalink
Merge pull request #7 from betrybe/adiciona-input-ignoreInlineConfig
Browse files Browse the repository at this point in the history
Adiciona input ignoreInlineConfig
  • Loading branch information
LeandroLM authored Nov 23, 2020
2 parents 5f6eca4 + b3be955 commit 54e9601
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 22 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: 'Tests'
on:
pull_request:
types: [opened, synchronize]

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm ci
- run: npm test
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,41 @@ This action accepts the following configuration parameters via `with:`

**Required**

The GitHub token to use for making API requests
The GitHub token to use for making API requests.

## Example usage
- `ignoreInlineConfig`

**Optional**

Set this option if inline configuration comments should be ignored on the analysis. The default is `true`.

## Usage

Basic:

```yaml
steps:
- uses: actions/setup-node@v1.4.4
with:
node-version: '12'
- name: Static code analysis step
uses: betrybe/eslint-linter-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
```
Allow inline configuration comments:
```yaml
steps:
- uses: actions/setup-node@v1.4.3
- uses: actions/setup-node@v1.4.4
with:
node-version: '12'
- name: Static code analysis step
uses: betrybe/eslint-linter-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
ignoreInlineConfig: false
```
Check the latest version to use [here](https://github.com/betrybe/eslint-linter-action/releases).
Expand Down
50 changes: 50 additions & 0 deletions __tests__/runEslintWithConfigFile.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
jest.mock('@actions/core');
jest.mock('child_process');

const { getInput } = require('@actions/core');
const { spawnSync } = require('child_process');
const eslintResultWithError = require('./fixtures/eslint-results/oneError.json');
const eslintResultWithoutError = require('./fixtures/eslint-results/frontEndNoError.json');
Expand All @@ -8,6 +10,7 @@ const runEslintWithConfigFile = require('../runEslintWithConfigFile');
describe('Running eslint', () => {
test('When there is an eslint config file to analyse and the analysis shows no issue, a success status is returned', () => {
spawnSync.mockReturnValue({ status: 0, stdout: JSON.stringify(eslintResultWithoutError) });
getInput.mockReturnValue('true');

const packageDirectory = '/path/to/project';
const packageFile = `${packageDirectory}/.eslintrc.json`;
Expand All @@ -33,6 +36,7 @@ describe('Running eslint', () => {
const emptyEslintResult = [];

spawnSync.mockReturnValue({ status: 0, stdout: JSON.stringify(emptyEslintResult) });
getInput.mockReturnValue('true');

const packageDirectory = '/path/to/project';
const packageFile = `${packageDirectory}/.eslintrc.json`;
Expand All @@ -56,6 +60,7 @@ describe('Running eslint', () => {

test('When there is an eslint config file to analyse and the analysis shows some issue, an error status is returned', () => {
spawnSync.mockReturnValue({ status: 1, stdout: JSON.stringify(eslintResultWithError) });
getInput.mockReturnValue('true');

const packageDirectory = '/path/to/project';
const packageFile = `${packageDirectory}/.eslintrc.json`;
Expand All @@ -76,4 +81,49 @@ describe('Running eslint', () => {
{ cwd: packageDirectory },
);
});

test('When the `ignoreInlineConfig` input is true, eslint is called with the `--no-inline-config` argument', () => {
getInput.mockReturnValue('true');

const packageDirectory = '/path/to/project';
const packageFile = `${packageDirectory}/.eslintrc.json`;

runEslintWithConfigFile(packageFile);

expect(spawnSync).toHaveBeenCalledWith(
'npx',
[
'eslint',
'-f', 'json',
'--no-inline-config',
'--ext', '.js, .jsx',
'--no-error-on-unmatched-pattern',
'-c', '.eslintrc.json',
'.'
],
{ cwd: packageDirectory },
);
});

test('When the `ignoreInlineConfig` input is false, eslint is called without the `--no-inline-config` argument', () => {
getInput.mockReturnValue('false');

const packageDirectory = '/path/to/project';
const packageFile = `${packageDirectory}/.eslintrc.json`;

runEslintWithConfigFile(packageFile);

expect(spawnSync).toHaveBeenCalledWith(
'npx',
[
'eslint',
'-f', 'json',
'--ext', '.js, .jsx',
'--no-error-on-unmatched-pattern',
'-c', '.eslintrc.json',
'.'
],
{ cwd: packageDirectory },
);
});
});
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ inputs:
token:
description: "The GitHub token to use for making API requests"
required: true
ignoreInlineConfig:
description: "Whether or not inline configurations should be ignored"
default: true
runs:
using: "node12"
main: "dist/index.js"
24 changes: 15 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4732,24 +4732,30 @@ exports.createTokenAuth = createTokenAuth;
/***/ 834:
/***/ (function(module, __unusedexports, __webpack_require__) {

const core = __webpack_require__(470);
const { spawnSync } = __webpack_require__(129);
const path = __webpack_require__(622);
const logProcessConclusion = __webpack_require__(234);

const runEslintWithConfigFile = (file) => {
console.log('-- found:', file);

const ignoreInlineConfig = core.getInput('ignoreInlineConfig') == 'true';

const args = [
'eslint',
'-f', 'json',
'--ext', '.js, .jsx',
'--no-error-on-unmatched-pattern',
'-c', path.basename(file),
'.',
];

if (ignoreInlineConfig) args.splice(3, 0, '--no-inline-config');

const eslintProcess = spawnSync(
'npx',
[
'eslint',
'-f', 'json',
'--no-inline-config',
'--ext', '.js, .jsx',
'--no-error-on-unmatched-pattern',
'-c', path.basename(file),
'.',
],
args,
{ cwd: path.dirname(file) },
);
const outcomes = JSON.parse(eslintProcess.stdout);
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"jest": "^26.4.0"
},
"jest": {
"testPathIgnorePatterns": ["__tests__/fixtures"]
"testPathIgnorePatterns": [
"__tests__/fixtures"
]
}
}
24 changes: 15 additions & 9 deletions runEslintWithConfigFile.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
const core = require('@actions/core');
const { spawnSync } = require('child_process');
const path = require('path');
const logProcessConclusion = require('./logProcessConclusion');

const runEslintWithConfigFile = (file) => {
console.log('-- found:', file);

const ignoreInlineConfig = core.getInput('ignoreInlineConfig') == 'true';

const args = [
'eslint',
'-f', 'json',
'--ext', '.js, .jsx',
'--no-error-on-unmatched-pattern',
'-c', path.basename(file),
'.',
];

if (ignoreInlineConfig) args.splice(3, 0, '--no-inline-config');

const eslintProcess = spawnSync(
'npx',
[
'eslint',
'-f', 'json',
'--no-inline-config',
'--ext', '.js, .jsx',
'--no-error-on-unmatched-pattern',
'-c', path.basename(file),
'.',
],
args,
{ cwd: path.dirname(file) },
);
const outcomes = JSON.parse(eslintProcess.stdout);
Expand Down

0 comments on commit 54e9601

Please sign in to comment.