kopia lustrzana https://github.com/c9/core
update eslint
rodzic
dc82e06477
commit
ed802cdccd
|
@ -0,0 +1,78 @@
|
||||||
|
var path = require("path");
|
||||||
|
var fs = require("fs");
|
||||||
|
|
||||||
|
function changeFile(filepath, handler) {
|
||||||
|
var value = fs.readFileSync(filepath, "utf8");
|
||||||
|
value = handler(value);
|
||||||
|
fs.writeFileSync(filepath, value, "utf8");
|
||||||
|
}
|
||||||
|
|
||||||
|
var loadRulesPath = require.resolve("eslint/lib/load-rules")
|
||||||
|
var contents = `module.exports = function() {
|
||||||
|
require("babel-polyfill");
|
||||||
|
var rules = {`;
|
||||||
|
|
||||||
|
fs.readdirSync(loadRulesPath + "/../rules").forEach(file => {
|
||||||
|
if (path.extname(file) == ".js") {
|
||||||
|
file = file.slice(0, -3);
|
||||||
|
contents += ' "' + file + '": ' + 'require("eslint/lib/rules/' + file + '"),\n';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
contents += `}\n
|
||||||
|
var jsxRules = require("eslint-plugin-react").rules;
|
||||||
|
Object.keys(jsxRules).forEach(function(key) { rules["react/" + key] = jsxRules[key]; })
|
||||||
|
return rules
|
||||||
|
};
|
||||||
|
`
|
||||||
|
changeFile(loadRulesPath, function() { return contents });
|
||||||
|
changeFile(require.resolve("eslint/lib/linter"), function(src) {
|
||||||
|
return src.replace('require(parserName)', 'require("espree")');
|
||||||
|
});
|
||||||
|
changeFile(require.resolve("espree/espree"), function(src) {
|
||||||
|
return src.replace(/acornOptions = {[^}\s]*/g, 'acornOptions = {allowImportExportEverywhere:true,')
|
||||||
|
.replace(/(function isValid(?:Node|Token)\(\w+\) {)(?!ret)/g, "$1return true;");
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var webpack = require("webpack");
|
||||||
|
var outputPath = __dirname + "/../worker/eslint_browserified.js"
|
||||||
|
webpack({
|
||||||
|
entry: "eslint/lib/linter",
|
||||||
|
module: {
|
||||||
|
rules: [{
|
||||||
|
test: /\.js$/,
|
||||||
|
include: [
|
||||||
|
path.resolve(__dirname)
|
||||||
|
],
|
||||||
|
enforce: 'pre',
|
||||||
|
loader: "babel-loader",
|
||||||
|
options: {
|
||||||
|
presets: ["es2015"],
|
||||||
|
compact: false
|
||||||
|
},
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
path: path.dirname(outputPath),
|
||||||
|
filename: path.basename(outputPath),
|
||||||
|
library: "eslint",
|
||||||
|
// libraryTarget: "window",
|
||||||
|
libraryTarget: "amd"
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
unsafeCache: true,
|
||||||
|
}
|
||||||
|
}, (err, stats) => {
|
||||||
|
if (err || stats.hasErrors()) {
|
||||||
|
console.log(err, stats)
|
||||||
|
}
|
||||||
|
var commentRe = /^(;)?(?:\s*(?:\/\/.+\n|\/\*(?:[^*]|\*(?!\/))*\*\/))+(?: *\n)?/gm;
|
||||||
|
changeFile(outputPath, function(src) {
|
||||||
|
return "// generated using packager/eslint.js"
|
||||||
|
+ src.replace(commentRe, "$1")
|
||||||
|
.replace('define("eslint", ', "define(");
|
||||||
|
})
|
||||||
|
});
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"babel": "^6.23.0",
|
||||||
|
"babel-core": "^6.26.0",
|
||||||
|
"babel-loader": "^7.1.2",
|
||||||
|
"babel-polyfill": "^6.26.0",
|
||||||
|
"babel-preset-es2015": "^6.24.1",
|
||||||
|
"eslint": "^4.11.0",
|
||||||
|
"eslint-plugin-react": "^7.4.0",
|
||||||
|
"webpack": "^3.8.1"
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
|
@ -8,7 +8,8 @@ define(function(require, exports, module) {
|
||||||
var baseLanguageHandler = require('plugins/c9.ide.language/base_handler');
|
var baseLanguageHandler = require('plugins/c9.ide.language/base_handler');
|
||||||
var workerUtil = require('plugins/c9.ide.language/worker_util');
|
var workerUtil = require('plugins/c9.ide.language/worker_util');
|
||||||
// var acorn = require("acorn/dist/acorn");
|
// var acorn = require("acorn/dist/acorn");
|
||||||
var linter = require("./eslint_browserified");
|
var Linter = require("./eslint_browserified");
|
||||||
|
var linter = new Linter();
|
||||||
var handler = module.exports = Object.create(baseLanguageHandler);
|
var handler = module.exports = Object.create(baseLanguageHandler);
|
||||||
var util = require("plugins/c9.ide.language/worker_util");
|
var util = require("plugins/c9.ide.language/worker_util");
|
||||||
var yaml = require("./js-yaml");
|
var yaml = require("./js-yaml");
|
||||||
|
@ -32,7 +33,7 @@ var defaultParserOptions = {
|
||||||
jsx: true, // enable JSX
|
jsx: true, // enable JSX
|
||||||
experimentalObjectRestSpread: true
|
experimentalObjectRestSpread: true
|
||||||
},
|
},
|
||||||
ecmaVersion: 6,
|
ecmaVersion: 8,
|
||||||
// sourceType: "module"
|
// sourceType: "module"
|
||||||
};
|
};
|
||||||
var defaultGlobals = require("plugins/c9.ide.language.javascript/scope_analyzer").GLOBALS;
|
var defaultGlobals = require("plugins/c9.ide.language.javascript/scope_analyzer").GLOBALS;
|
||||||
|
@ -77,10 +78,10 @@ handler.init = function(callback) {
|
||||||
rules["handle-callback-err"] = 1;
|
rules["handle-callback-err"] = 1;
|
||||||
rules["no-new-require"] = 2;
|
rules["no-new-require"] = 2;
|
||||||
|
|
||||||
for (var r in rules) {
|
// for (var r in rules) {
|
||||||
if (!(r in linter.defaults().rules))
|
// if (!(r in linter.defaults().rules))
|
||||||
throw new Error("Unknown rule: ", r);
|
// throw new Error("Unknown rule: ", r);
|
||||||
}
|
// }
|
||||||
|
|
||||||
loadConfigFile(true, function(err) {
|
loadConfigFile(true, function(err) {
|
||||||
if (err) console.error(err);
|
if (err) console.error(err);
|
||||||
|
@ -159,7 +160,7 @@ handler.analyzeSync = function(value, ast, path) {
|
||||||
config.globals = config.globals || defaultGlobals;
|
config.globals = config.globals || defaultGlobals;
|
||||||
config.parserOptions = config.parserOptions || defaultParserOptions;
|
config.parserOptions = config.parserOptions || defaultParserOptions;
|
||||||
if (config.parserOptions.ecmaVersion == null)
|
if (config.parserOptions.ecmaVersion == null)
|
||||||
config.parserOptions.ecmaVersion = 7;
|
config.parserOptions.ecmaVersion = 8;
|
||||||
if (config.parserOptions.ecmaFeatures == null)
|
if (config.parserOptions.ecmaFeatures == null)
|
||||||
config.parserOptions.ecmaFeatures = defaultParserOptions.ecmaFeatures;
|
config.parserOptions.ecmaFeatures = defaultParserOptions.ecmaFeatures;
|
||||||
if (config.parserOptions.ecmaFeatures.experimentalObjectRestSpread == null)
|
if (config.parserOptions.ecmaFeatures.experimentalObjectRestSpread == null)
|
||||||
|
@ -172,7 +173,7 @@ handler.analyzeSync = function(value, ast, path) {
|
||||||
args: handler.isFeatureEnabled("unusedFunctionArgs") ? "all" : "none"
|
args: handler.isFeatureEnabled("unusedFunctionArgs") ? "all" : "none"
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
config.rules["jsx-uses-vars"] = 2;
|
config.rules["react/jsx-uses-vars"] = 2;
|
||||||
config.rules["no-undef"] =
|
config.rules["no-undef"] =
|
||||||
handler.isFeatureEnabled("undeclaredVars") ? 1 : 0;
|
handler.isFeatureEnabled("undeclaredVars") ? 1 : 0;
|
||||||
|
|
||||||
|
@ -221,6 +222,7 @@ handler.analyzeSync = function(value, ast, path) {
|
||||||
|
|
||||||
// work around column offset bug
|
// work around column offset bug
|
||||||
m.column--;
|
m.column--;
|
||||||
|
m.line--;
|
||||||
|
|
||||||
var ec;
|
var ec;
|
||||||
if (m.message.match(/is not defined|was used before it was defined|is already declared|is already defined|unexpected identifier|defined but never used/i)) {
|
if (m.message.match(/is not defined|was used before it was defined|is already declared|is already defined|unexpected identifier|defined but never used/i)) {
|
||||||
|
|
Ładowanie…
Reference in New Issue