mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-10-27 16:41:37 +03:00
Remove lintingDir
This commit is contained in:
parent
0470d19af8
commit
7f37ee4c68
@ -1,72 +0,0 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs-extra');
|
||||
const glob = require('glob');
|
||||
|
||||
const defaultGlob = '**/*.elm';
|
||||
const ignore = ['**/elm-stuff/**', '**/node_modules/**', 'lintingDir/**'];
|
||||
|
||||
function flatMap(array, fn) {
|
||||
return array.reduce((res, item) => res.concat(fn(item)), []);
|
||||
}
|
||||
|
||||
function getFiles(filename) {
|
||||
if (!fs.existsSync(filename)) {
|
||||
return [];
|
||||
}
|
||||
if (fs.lstatSync(filename).isDirectory()) {
|
||||
return flatMap(
|
||||
glob.sync('/' + defaultGlob, {
|
||||
root: filename,
|
||||
nocase: true,
|
||||
ignore: ['/**/elm-stuff/**', '/**/node_modules/**'],
|
||||
nodir: true
|
||||
}),
|
||||
resolveFilePath
|
||||
);
|
||||
}
|
||||
return [filename];
|
||||
}
|
||||
|
||||
// Recursively search directories for *.elm files, excluding elm-stuff/
|
||||
function resolveFilePath(filename) {
|
||||
// Exclude everything having anything to do with elm-stuff
|
||||
return getFiles(filename).filter(candidate => !candidate.split(path.sep).includes('elm-stuff'));
|
||||
}
|
||||
|
||||
function globify(filename) {
|
||||
return glob.sync(filename, {
|
||||
nocase: true,
|
||||
ignore: ignore,
|
||||
nodir: false
|
||||
});
|
||||
}
|
||||
|
||||
function globifyWithRoot(root, filename) {
|
||||
return glob.sync(filename, {
|
||||
root: root,
|
||||
nocase: true,
|
||||
ignore: ignore,
|
||||
nodir: false
|
||||
});
|
||||
}
|
||||
|
||||
function getElmFilePaths(filePathArgs) {
|
||||
if (filePathArgs.length > 0) {
|
||||
return flatMap(filePathArgs, globify);
|
||||
}
|
||||
|
||||
const root = path.join(path.resolve(process.cwd()), '..');
|
||||
return globifyWithRoot(root, '**/*.elm');
|
||||
}
|
||||
|
||||
function getElmFiles(filePathArgs) {
|
||||
const relativeElmFiles = getElmFilePaths(filePathArgs);
|
||||
return flatMap(relativeElmFiles, resolveFilePath).map(file => {
|
||||
return {
|
||||
filename: file,
|
||||
source: fs.readFileSync(file, 'utf8')
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = getElmFiles;
|
@ -1,19 +0,0 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"Bogdanp/elm-ast": "8.0.3 <= v < 9.0.0",
|
||||
"elm-community/list-extra": "5.0.1 <= v < 6.0.0",
|
||||
"elm-community/parser-combinators": "1.1.0 <= v < 2.0.0",
|
||||
"elm-lang/core": "5.0.0 <= v < 6.0.0",
|
||||
"elm-lang/html": "2.0.0 <= v < 3.0.0"
|
||||
},
|
||||
"version": "1.0.0",
|
||||
"summary": "Linting binary",
|
||||
"repository": "https://github.com/jfmengels/elm-lint.git",
|
||||
"license": "BSD3",
|
||||
"source-directories": [
|
||||
"src",
|
||||
"../src"
|
||||
],
|
||||
"exposed-modules": [],
|
||||
"elm-version": "0.18.0 <= v < 0.19.0"
|
||||
}
|
69
lintingDir/package-lock.json
generated
69
lintingDir/package-lock.json
generated
@ -1,69 +0,0 @@
|
||||
{
|
||||
"name": "lintingDir",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"dependencies": {
|
||||
"balanced-match": {
|
||||
"version": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz",
|
||||
"integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI="
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
|
||||
},
|
||||
"fs-extra": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-3.0.1.tgz",
|
||||
"integrity": "sha1-N5TzeMWLNC6n27sjCVEJxLO2IpE="
|
||||
},
|
||||
"fs.realpath": {
|
||||
"version": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
|
||||
},
|
||||
"glob": {
|
||||
"version": "7.1.2",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
|
||||
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ=="
|
||||
},
|
||||
"graceful-fs": {
|
||||
"version": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz",
|
||||
"integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg="
|
||||
},
|
||||
"inflight": {
|
||||
"version": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
||||
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk="
|
||||
},
|
||||
"inherits": {
|
||||
"version": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
|
||||
},
|
||||
"jsonfile": {
|
||||
"version": "https://registry.npmjs.org/jsonfile/-/jsonfile-3.0.0.tgz",
|
||||
"integrity": "sha1-kufHRE5f/V+jLmqa6LhQNN+DR9A="
|
||||
},
|
||||
"minimatch": {
|
||||
"version": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||
"integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM="
|
||||
},
|
||||
"once": {
|
||||
"version": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E="
|
||||
},
|
||||
"path-is-absolute": {
|
||||
"version": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
|
||||
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
|
||||
},
|
||||
"universalify": {
|
||||
"version": "https://registry.npmjs.org/universalify/-/universalify-0.1.0.tgz",
|
||||
"integrity": "sha1-nrHEZR3rzGcMyU8adXYjMruWd3g="
|
||||
},
|
||||
"wrappy": {
|
||||
"version": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
{
|
||||
"name": "lintingDir",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "ok.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"fs-extra": "^3.0.1",
|
||||
"glob": "^7.1.2"
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const getElmFiles = require('./elm-files')
|
||||
const Elm = require('./compiledLintApp');
|
||||
|
||||
const elmFiles = getElmFiles([]);
|
||||
if (elmFiles.length === 0) {
|
||||
console.error('Could not find any files to lint.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const app = Elm.LintApp.worker();
|
||||
|
||||
app.ports.linting.send(elmFiles);
|
||||
|
||||
app.ports.resultPort.subscribe(function(report) {
|
||||
console.log(report);
|
||||
});
|
@ -1,108 +0,0 @@
|
||||
port module LintApp exposing (..)
|
||||
|
||||
import Json.Decode
|
||||
import Lint exposing (lintSource)
|
||||
import Lint.Types exposing (LintRule, LintError, Severity(..))
|
||||
import LintConfig exposing (config)
|
||||
|
||||
|
||||
type alias File =
|
||||
{ filename : String
|
||||
, source : String
|
||||
}
|
||||
|
||||
|
||||
port linting : (List File -> msg) -> Sub msg
|
||||
|
||||
|
||||
port resultPort : String -> Cmd msg
|
||||
|
||||
|
||||
type alias Model =
|
||||
{}
|
||||
|
||||
|
||||
type Msg
|
||||
= Lint (List File)
|
||||
|
||||
|
||||
enabledRules : List ( Severity, LintRule )
|
||||
enabledRules =
|
||||
config
|
||||
|> List.filter (Tuple.first >> (/=) Disabled)
|
||||
|
||||
|
||||
lint : String -> List ( Severity, LintError )
|
||||
lint source =
|
||||
lintSource enabledRules source
|
||||
|> (\result ->
|
||||
case result of
|
||||
Err errors ->
|
||||
[ ( Critical, { rule = "ParseError", message = String.join "\n" errors } )
|
||||
]
|
||||
|
||||
Ok result ->
|
||||
result
|
||||
)
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
Lint files ->
|
||||
let
|
||||
lintResult =
|
||||
files
|
||||
|> List.map (\file -> ( file, lint file.source ))
|
||||
|> List.filter
|
||||
(Tuple.second >> List.isEmpty >> not)
|
||||
|> List.map formatReport
|
||||
|> String.join "\n\n"
|
||||
in
|
||||
( model
|
||||
, resultPort lintResult
|
||||
)
|
||||
|
||||
|
||||
subscriptions : Model -> Sub Msg
|
||||
subscriptions model =
|
||||
linting Lint
|
||||
|
||||
|
||||
main : Program Never Model Msg
|
||||
main =
|
||||
Platform.program
|
||||
{ init = ( Model, Cmd.none )
|
||||
, update = update
|
||||
, subscriptions = subscriptions
|
||||
}
|
||||
|
||||
|
||||
formatSeverity : Severity -> String
|
||||
formatSeverity severity =
|
||||
case severity of
|
||||
Disabled ->
|
||||
"Disabled"
|
||||
|
||||
Warning ->
|
||||
"Warning"
|
||||
|
||||
Critical ->
|
||||
"Critical"
|
||||
|
||||
|
||||
formatReport : ( File, List ( Severity, LintError ) ) -> String
|
||||
formatReport ( { filename }, errors ) =
|
||||
let
|
||||
formattedErrors =
|
||||
List.map
|
||||
(\( severity, { rule, message } ) ->
|
||||
"(" ++ (formatSeverity severity) ++ ") " ++ rule ++ ": " ++ message
|
||||
)
|
||||
errors
|
||||
in
|
||||
(toString (List.length errors))
|
||||
++ " errors found in '"
|
||||
++ filename
|
||||
++ "':\n\n\t"
|
||||
++ (String.join "\n\t" formattedErrors)
|
@ -1,36 +0,0 @@
|
||||
module LintConfig exposing (config)
|
||||
|
||||
import Lint.Types exposing (LintRule, Severity(..))
|
||||
import Lint.Rules.DefaultPatternPosition
|
||||
import Lint.Rules.NoConstantCondition
|
||||
import Lint.Rules.NoDebug
|
||||
import Lint.Rules.NoDuplicateImports
|
||||
import Lint.Rules.NoExposingEverything
|
||||
import Lint.Rules.NoImportingEverything
|
||||
import Lint.Rules.NoNestedLet
|
||||
import Lint.Rules.NoUnannotatedFunction
|
||||
import Lint.Rules.NoUnusedVariables
|
||||
import Lint.Rules.NoUselessIf
|
||||
import Lint.Rules.NoUselessPatternMatching
|
||||
import Lint.Rules.NoWarningComments
|
||||
import Lint.Rules.SimplifyPiping
|
||||
import Lint.Rules.SimplifyPropertyAccess
|
||||
|
||||
|
||||
config : List ( Severity, LintRule )
|
||||
config =
|
||||
[ ( Critical, Lint.Rules.DefaultPatternPosition.rule { position = Lint.Rules.DefaultPatternPosition.Last } )
|
||||
, ( Critical, Lint.Rules.NoConstantCondition.rule )
|
||||
, ( Critical, Lint.Rules.NoDebug.rule )
|
||||
, ( Critical, Lint.Rules.NoDuplicateImports.rule )
|
||||
, ( Critical, Lint.Rules.NoExposingEverything.rule )
|
||||
, ( Critical, Lint.Rules.NoImportingEverything.rule )
|
||||
, ( Critical, Lint.Rules.NoNestedLet.rule )
|
||||
, ( Critical, Lint.Rules.NoUnannotatedFunction.rule )
|
||||
, ( Critical, Lint.Rules.NoUnusedVariables.rule )
|
||||
, ( Critical, Lint.Rules.NoUselessIf.rule )
|
||||
, ( Critical, Lint.Rules.NoUselessPatternMatching.rule )
|
||||
, ( Warning, Lint.Rules.NoWarningComments.rule )
|
||||
, ( Critical, Lint.Rules.SimplifyPiping.rule )
|
||||
, ( Critical, Lint.Rules.SimplifyPropertyAccess.rule )
|
||||
]
|
Loading…
Reference in New Issue
Block a user