A GitHub action that evaluates projects with ESLint and comments the evaluation outcome on the student's pull request.
dist/index.js to execute this action, so you must run npm run pack and commit the changes made at dist/index.js if you want to apply any changes.
Install the dependencies
$ npm installRun the tests ⚗️
$ npm testGitHub Actions will run the entry point from the action.yml. Packaging assembles the code into one file that can be checked in to Git, enabling fast and reliable execution and preventing the need to check in node_modules.
Actions are run from GitHub repos. Packaging the action will create a packaged action in the dist folder.
Run package
npm run packSince the packaged index.js is run from the dist folder.
git add distThis action accepts the following configuration parameters via with:
-
tokenRequired
The GitHub token to use for making API requests.
-
ignoreInlineConfigOptional
Set this option if inline configuration comments should be ignored on the analysis. The default is
true. -
pr_numberRequired
Pull Request number that dispatched the workflow.
Basic:
steps:
- uses: actions/setup-node@v1.4.4
with:
node-version: '12'
- name: Static code analysis step
uses: betrybe/eslint-linter-action@v3.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
pr_number: ${{ github.event.inputs.pr_number }}To projects running Nodejs16:
steps:
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Static code analysis step
uses: betrybe/eslint-linter-action@v3.3
with:
token: ${{ secrets.GITHUB_TOKEN }}
pr_number: ${{ github.event.inputs.pr_number }}Allow inline configuration comments:
steps:
- uses: actions/setup-node@v1.4.4
with:
node-version: '12'
- name: Static code analysis step
uses: betrybe/eslint-linter-action@v3.3
with:
token: ${{ secrets.GITHUB_TOKEN }}
pr_number: ${{ github.event.inputs.pr_number }}
ignoreInlineConfig: falseCheck the latest version to use here.
In order for the action to comment the ESLint analysis on the pull request, you must:
-
Add
ESLintinto your project's dependencies. -
Configure the
ESLintanalysis exclusively via.eslintrc.json.
In order to add ESLint into your project you must add ESLint as a dev dependency:
npm install eslint --save-devIf you have multiple projects to be evaluated with ESLint in the repository, you must add ESLint to each project. Beware that each project must have the same ESLint version, in order to ensure that all projects are being evaluated under the same conditions (i.e., the same ESLint version).
In order to configure the ESLint analysis for your project, you must create a .eslintrc.json file at the root of your project. Therefore, beware the following:
-
There cannot be present
ESLintconfigurations in thepackage.jsonof the project; -
There cannot be present inline configurations.
Here follows an example for .eslintrc.json:
{
"env": {
"es6": true
},
"parserOptions": {
"ecmaVersion": 6
},
"rules": {
"no-console": "error",
"semi": "error",
"max-params": ["error", 2]
}
}If you have multiple projects to be evaluated with ESLint in the repository, you must do the following:
-
Create a
.eslintrc.jsonfile at the root of each project. There cannot be present a.eslintrc.jsonat the root of the repository; -
Add
"root": truefor each.eslintrc.json, in order to ensure theESLintanalysis for one project does not useESLintconfigured in another project in your repository.
Here follows an example for .eslintrc.json defined in one of the projects in your repository:
{
"root": true,
"env": {
"es6": true
},
"parserOptions": {
"ecmaVersion": 6
},
"rules": {
"no-console": "error",
"semi": "error",
"max-params": ["error", 2]
}
}You can use plugins in the configuration file .eslintrc.json. However, beware to follow the instructions as stated in the plugin's documentation and install all dependencies associated with the plugin. There cannot be any warning raised by npm stating uninstalled plugin dependencies when installing a project; otherwise you will have an incomplete ESLint analysis environment.
For more information related to configuring ESLint with .eslintrc.json, read its guide.
Users shouldn't consume the action from master since that would be latest code and actions can break compatibility between major versions.
Checking to the v1 release branch
$ git checkout -b v1
$ git commit -a -m "v1 release"$ git push origin v1Your action is now published! 🚀
See the versioning documentation
You can now consume the action by referencing the v1 branch
uses: betrybe/eslint-linter-action@v1See the actions tab for runs of this action! 🚀