Skip to content

Commit

Permalink
Linter uses tooling API
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohnson committed Oct 9, 2017
1 parent ab96233 commit 4197163
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
42 changes: 14 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
var babylonToEspree = require("./babylon-to-espree");
var pick = require("lodash.pickby");
var isEmpty = require("lodash/isEmpty");
var Module = require("module");
var path = require("path");
var jsParse = require("babylon").parse;
var babel = require("babel-core");
var lscPlugin = require("@oigroup/babel-plugin-lightscript");
var lscConfig = require("@oigroup/babel-plugin-lightscript/lib/config");
var parseConfigurationDirectives = require("@oigroup/babel-plugin-lightscript/lib/util/parseConfigurationDirectives");
var t = require("babel-types");
var tt = require("@oigroup/babylon-lightscript").tokTypes;
var tt = require("babylon").tokTypes;
var traverse = require("babel-traverse").default;
var codeFrame = require("babel-code-frame");

var lscPlugin = require("@oigroup/babel-plugin-lightscript");
var lscTooling = require("@oigroup/babel-plugin-lightscript/lib/tooling");

var hasPatched = false;
var eslintOptions = {};

Expand Down Expand Up @@ -450,38 +449,25 @@ exports.parseNoPatch = function (code, options) {
// and come up with all this stuff.
// (This setup step should also read .babelrc)
var filePath = options.filePath;
var configOpts = parseConfigurationDirectives(code);
var useLsc = (configOpts.isLightScript || !filePath || /\.(lsc|lsx)/.test(filePath) || filePath === "unknown");
var compilerConfig = lscTooling.getCompilerConfiguration(filePath, code, { __linter: true });
var useLsc = compilerConfig.isLightScript;

var ast;
try {
if (useLsc) {
if (isEmpty(configOpts)) {
configOpts = {
existential: true,
flippedImports: true,
noEnforcedSubscriptIndentation: true,
safeCall: true,
placeholderArgs: true,
pipeCall: true,
__linter: true
};
} else {
configOpts.__linter = true;
}
tt = lscTooling.babylon.tokTypes;

const parserOpts = lscConfig.getParserOpts(configOpts);
parserOpts.sourceType = options.sourceType;
parserOpts.allowImportExportEverywhere = options.allowImportExportEverywhere;
parserOpts.allowReturnOutsideFunction = true;
parserOpts.allowSuperOutsideMethod = true;
ast = lscTooling.parse(compilerConfig, code, {
sourceType: options.sourceType,
allowImportExportEverywhere: options.allowImportExportEverywhere,
allowReturnOutsideFunction: true,
allowSuperOutsideMethod: true
});

ast = parserOpts.parser(code, parserOpts);
// ast = lscParse(code, parserOpts);
// run it through babel-plugin-lightscript to throw errors
const { ast: nextAst } = babel.transformFromAst(ast, code, {
code: false,
plugins: [[lscPlugin, configOpts]],
plugins: [[lscPlugin, compilerConfig]],
});
nextAst.tokens = ast.tokens;
ast = nextAst;
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
},
"dependencies": {
"@oigroup/babel-plugin-lightscript": "3.0.0-alpha.6",
"@oigroup/babylon-lightscript": "3.0.0-alpha.6",
"babylon": "^6.18.0",
"babel-code-frame": "^6.22.0",
"babel-core": "^6.25.0",
"babel-traverse": "^6.25.0",
"babel-types": "^6.25.0",
"babylon": "^6.17.4",
"lodash": "^4.17.4",
"lodash.pickby": "^4.6.0"
},
Expand Down
6 changes: 5 additions & 1 deletion test/non-regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ x = if a: b else: c

it("ExistentialExpression", () => {
verifyAndAssertMessages(
"x?",
unpad(`
'use @oigroup/lightscript with existential'
x?
`),
{},
[]
);
Expand Down Expand Up @@ -410,6 +413,7 @@ a
it("placeholder args", () => {
verifyAndAssertMessages(
unpad(`
'use @oigroup/lightscript with placeholderArgs'
x = -> [_, ..._]
y = -> [_0, ..._]
`),
Expand Down

0 comments on commit 4197163

Please sign in to comment.