mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-12-27 03:33:00 +03:00
Lint files dynamically
This commit is contained in:
parent
992bdb88ea
commit
c20be88081
73
lintingDir/elm-files.js
Normal file
73
lintingDir/elm-files.js
Normal file
@ -0,0 +1,73 @@
|
||||
const path = require('path');
|
||||
const _ = require('lodash');
|
||||
const fs = require('fs-extra');
|
||||
const glob = require('glob');
|
||||
|
||||
const defaultGlob = '**/*.elm';
|
||||
const ignore = ['**/elm-stuff/**', '**/node_modules/**', 'lintingDir/**'];
|
||||
|
||||
function getFiles(filename) {
|
||||
if (!fs.existsSync(filename)) {
|
||||
return [];
|
||||
}
|
||||
if (fs.lstatSync(filename).isDirectory()) {
|
||||
console.log(candidate);
|
||||
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;
|
74
lintingDir/package-lock.json
generated
Normal file
74
lintingDir/package-lock.json
generated
Normal file
@ -0,0 +1,74 @@
|
||||
{
|
||||
"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="
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.4",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz",
|
||||
"integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4="
|
||||
},
|
||||
"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="
|
||||
}
|
||||
}
|
||||
}
|
17
lintingDir/package.json
Normal file
17
lintingDir/package.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"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",
|
||||
"lodash": "^4.17.4"
|
||||
}
|
||||
}
|
@ -1,13 +1,18 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const Elm = require('./ok');
|
||||
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({
|
||||
filename: 'SomeFile.elm',
|
||||
source: "add a b = a + b"
|
||||
});
|
||||
|
||||
app.ports.linting.send(elmFiles);
|
||||
|
||||
app.ports.resultPort.subscribe(function(result) {
|
||||
console.log('result', result)
|
||||
// app.ports.suggestions.send(suggestions);
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
});
|
||||
|
@ -13,10 +13,10 @@ type alias File =
|
||||
}
|
||||
|
||||
|
||||
port linting : (File -> msg) -> Sub msg
|
||||
port linting : (List File -> msg) -> Sub msg
|
||||
|
||||
|
||||
port resultPort : ( File, List String ) -> Cmd msg
|
||||
port resultPort : List ( File, List String ) -> Cmd msg
|
||||
|
||||
|
||||
type alias Model =
|
||||
@ -24,7 +24,7 @@ type alias Model =
|
||||
|
||||
|
||||
type Msg
|
||||
= Lint File
|
||||
= Lint (List File)
|
||||
|
||||
|
||||
lint : String -> List String
|
||||
@ -45,10 +45,9 @@ init =
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
update msg model =
|
||||
case msg of
|
||||
Lint file ->
|
||||
Lint files ->
|
||||
( model
|
||||
, resultPort
|
||||
( file, lint file.source )
|
||||
, resultPort (List.map (\file -> ( file, lint file.source )) files)
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user