Skip to content

Commit

Permalink
Setup Mega-Linter Github Action (#120)
Browse files Browse the repository at this point in the history
* Setup Mega-Linter Github Action

https://github.com/nvuillam/mega-linter#readme

* Validate all sources

* Filter test folder

* Fix typos and add whitelisted words for cSpell

* Update README to add Mega-Linter badge

* Now all sources are fixed, validate only diff at each push/pr

* Fix markdown and typos

* Update .gitignore to ignore Mega-Linter logs
  • Loading branch information
nvuillam authored Nov 10, 2020
1 parent 66d828f commit 6f74142
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 31 deletions.
50 changes: 50 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"version": "0.1",
"language": "en",
"words": [
"agda",
"Brightscript",
"Codemetrics",
"codemetrics",
"COPYPASTE",
"extname",
"exts",
"fetchgit",
"fetchurl",
"fmts",
"keyvalue",
"kohlhase",
"Kohlhase",
"Haxe",
"Helvetica",
"httprequest",
"lerp",
"lineize",
"lstat",
"typeof",
"markus",
"Markus",
"maxlines",
"mochi",
"multiline",
"nixpkgs",
"nvuillam",
"oohh",
"pkgs",
"Println",
"programm",
"readdirp",
"Ren'Py",
"sloc",
"sloccount",
"stdenv",
"stefanzweifel",
"styl",
"substr",
"testfiles",
"TODO's",
"TURE",
"xlink"
],
"flagWords": []
}
81 changes: 81 additions & 0 deletions .github/workflows/mega-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
# Mega-Linter GitHub Action configuration file
# More info at https://github.com/nvuillam/mega-linter#readme
name: Mega-Linter

on:
# Trigger mega-linter at every push. Action will also be visible from Pull Requests to master
push: # Comment this line to trigger action only on pull-requests (not recommended if you don't pay for GH Actions)
pull_request:
branches: [master]

env: #Uncomment to activate variables below
# Apply linter fixes configuration
APPLY_FIXES: all # Uncomment to apply fixes provided by linters. You can also specify the list of fixing linters
APPLY_FIXES_EVENT: pull_request # Decide which event triggers application of fixes in a commit or a PR (pull_request (default), push, all)
APPLY_FIXES_MODE: commit # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request)

jobs:
build:
name: Mega-Linter
runs-on: ubuntu-latest
steps:
# Git Checkout
- name: Checkout Code
uses: actions/checkout@v2
with:
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
fetch-depth: 0

# Mega-Linter
- name: Mega-Linter
uses: nvuillam/mega-linter@insiders
env:
# All available variables are described in documentation
# https://github.com/nvuillam/mega-linter#configuration
VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} # Validates all source when push on master, else just the git diff with master. Override with true if you always want to lint all sources
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# DISABLE: COPYPASTE,SPELL
FILTER_REGEX_EXCLUDE: (/github/workspace/spec/testfiles/)

# Upload Mega-Linter artifacts. They will be available on Github action page "Artifacts" section
- name: Archive production artifacts
if: ${{ success() }} || ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: Mega-Linter reports
path: |
report
mega-linter.log
# This step will evaluate the repo status and report the change
- name: Check if there are changes
id: changes
if: ${{ success() }} || ${{ failure() }}
uses: UnicornGlobal/has-changes-action@v1.0.11

# Create pull request if applicable
- name: Create Pull Request with applied fixes
if: steps.changes.outputs.changed == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request'
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
commit-message: "[Mega-Linter] Apply linters automatic fixes"
title: "[Mega-Linter] Apply linters automatic fixes"
labels: bot
- name: Create PR output
if: steps.changes.outputs.changed == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request'
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
# Push new commit if applicable
- name: Prepare commit
if: steps.changes.outputs.changed == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/master'
run: sudo chown -Rc $UID .git/
- name: Commit and push applied linter fixes
if: steps.changes.outputs.changed == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/master'
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }}
commit_message: "[Mega-Linter] Apply linters fixes"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ lib/
*.bak
*.tmp
npm-debug.log
*.log
report/
59 changes: 32 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Create stats of your source code:
[![Dependency Status](https://gemnasium.com/flosse/sloc.svg)](https://gemnasium.com/flosse/sloc)
[![NPM version](https://badge.fury.io/js/sloc.svg)](http://badge.fury.io/js/sloc)
[![Bower version](https://img.shields.io/bower/v/sloc.svg)](https://github.com/flosse/sloc)
[![Mega-Linter](https://github.com/flosse/sloc/workflows/Mega-Linter/badge.svg?branch=master)](https://github.com/nvuillam/mega-linter#readme)
[![License](https://img.shields.io/npm/l/sloc.svg)](https://github.com/flosse/sloc/blob/master/LICENCE.txt)
[![Minified size](http://img.shields.io/badge/size-6,1K-blue.svg)](https://github.com/flosse/sloc)

Expand All @@ -25,19 +26,19 @@ In addition to the default terminal output (see examples below), sloc provides a

- CSV
- JSON
- Commandline table
- Command line table

## Install

To use sloc as an application install it globally:

```
```shell
sudo npm install -g sloc
```

If you're going to use it as a Node.js module within your project:

```
```shell
npm install --save sloc
```

Expand All @@ -53,43 +54,43 @@ Link `sloc.js` in your HTML file:

sloc is also available via [bower](http://twitter.github.com/bower/):

```
```shell
bower install sloc
```

**Note**:
You need to compile the coffee-script files yourself.
If you want to use a precompiled bower package, you can run
If you want to use a pre-compiled bower package, you can run

```
```shell
bower install sloc-bower
```

## Usage

### CLI

```
```shell
sloc [option] <file>|<directory>
```

Options:

```
```shell
-h, --help output usage information
-V, --version output the version number
-e, --exclude <regex> regular expression to exclude files and folders
-i, --include <regex> regular expression to include files and folders
-f, --format <format> format output: json, csv, cli-table
--format-option [value] add formatter option
-k, --keys <keys> report only numbers of the given keys
-d, --details report stats of each analzed file
-d, --details report stats of each analyzed file
-a, --alias <custom ext>=<standard ext> alias custom ext to act like standard ext (eg. php5=php,less=css)
```

e.g.:

```
```shell
$ sloc src/

---------- Result ------------
Expand All @@ -109,7 +110,7 @@ Number of files read : 10

or

```
```shell
$ sloc --details \
--format cli-table \
--keys total,source,comment \
Expand Down Expand Up @@ -152,7 +153,7 @@ fs.readFile("mySourceFile.coffee", "utf8", function(err, code){
});
```

### Browser
### Browser usage

```javascript
var sourceCode = "foo();\n /* bar */\n baz();";
Expand All @@ -177,29 +178,29 @@ var stats = window.sloc(sourceCode,"javascript");
### sloc adapters

- Grunt
- [grunt-sloc](https://github.com/rhiokim/grunt-sloc).
- [grunt-sloccount](https://github.com/asciidisco/grunt-sloccount)
- [grunt-maxlines](https://github.com/zerok/grunt-maxlines)
- [grunt-file-sloc](https://github.com/bubkoo/grunt-file-sloc)
- [grunt-sloc](https://github.com/rhiokim/grunt-sloc).
- [grunt-sloccount](https://github.com/asciidisco/grunt-sloccount)
- [grunt-maxlines](https://github.com/zerok/grunt-maxlines)
- [grunt-file-sloc](https://github.com/bubkoo/grunt-file-sloc)

- Gulp
- [gulp-sloc](https://github.com/oddjobsman/gulp-sloc):
- [gulp-sloc2](https://github.com/pnarielwala/gulp-sloc2)
- [gulp-sloc](https://github.com/oddjobsman/gulp-sloc):
- [gulp-sloc2](https://github.com/pnarielwala/gulp-sloc2)

- [Atom](https://atom.io/)

- [atom-sloc](https://github.com/sgade/atom-sloc)
- [line-count](https://github.com/mark-hahn/line-count)
- [atom-sloc](https://github.com/sgade/atom-sloc)
- [line-count](https://github.com/mark-hahn/line-count)

- Jenkins
- [sloc-for-jenkins](https://www.npmjs.com/package/sloc-for-jenkins)
- [sloccount](https://github.com/asciidisco/sloccount)
- [sloc-for-jenkins](https://www.npmjs.com/package/sloc-for-jenkins)
- [sloccount](https://github.com/asciidisco/sloccount)

- Istanbbul
- [istanbul-reporter-clover-limits](https://github.com/Cellarise/istanbul-reporter-clover-limits/)
- Istanbul
- [istanbul-reporter-clover-limits](https://github.com/Cellarise/istanbul-reporter-clover-limits/)

- Codemetrics
- [codemetrics-process-sloc](https://github.com/maxdow/codemetrics-process-sloc)
- [codemetrics-process-sloc](https://github.com/maxdow/codemetrics-process-sloc)

## Supported languages

Expand Down Expand Up @@ -261,11 +262,15 @@ var stats = window.sloc(sourceCode,"javascript");

## Run tests

npm test
```shell
npm test
```

## Build

npm run prepublish
```shell
npm run prepublish
```

## Changelog

Expand Down
6 changes: 3 additions & 3 deletions spec/languages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ module.exports =
source() /* one line block */
/* one line block */ code()
/* block */ code() /*
*/ souce() # comment /* no block */
*/ source() # comment /* no block */
"""
comment: 9
source: 5
Expand Down Expand Up @@ -521,7 +521,7 @@ module.exports =
source() =begin one line block=end
=begin one line block =end code()
=begin block =end code() =begin
=end souce() # comment =begin no block =end
=end source() # comment =begin no block =end
"""
comment: 9
source: 5
Expand Down Expand Up @@ -715,7 +715,7 @@ module.exports =
"""
// comment
body
font: 100% Helvecia, sans-serif /* multi
font: 100% Helvetica, sans-serif /* multi
line comments */
"""
comment: 3
Expand Down
2 changes: 1 addition & 1 deletion spec/sloc.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe "The sloc module", ->
res.todo.should.equal 0
done()

it "evaluates an emty file correctly", (done) ->
it "evaluates an empty file correctly", (done) ->
fs.readFile "./spec/testfiles/empty.js", "utf-8", (err, code) ->
res = sloc code, "js"
res.empty.should.equal 1
Expand Down

0 comments on commit 6f74142

Please sign in to comment.