Add a lint plugin to ensure we only use ES5 syntax. (#3160)

* Add a lint plugin to ensure we only use ES5 only syntax.
This commit is contained in:
Sam El-Husseini
2019-10-21 21:26:26 -04:00
committed by GitHub
parent ff067497fc
commit 6d8f22f39a
7 changed files with 35 additions and 19 deletions

View File

@@ -74,7 +74,8 @@
"balanced": true
},
"exceptions": ["*"]
}]
}],
"es5/no-es6-methods": ["warn"]
},
"env": {
"browser": true
@@ -83,5 +84,8 @@
"Blockly": true,
"goog": true
},
"extends": "eslint:recommended"
"extends": [
"eslint:recommended",
"plugin:es5/no-es2015"
]
}

View File

@@ -55,7 +55,9 @@ Blockly.utils.object.mixin = function(target, source) {
*/
Blockly.utils.object.values = function(obj) {
if (Object.values) {
/* eslint-disable es5/no-es6-methods */
return Object.values(obj);
/* eslint-enable es5/no-es6-methods */
}
// Fallback for IE.
return Object.keys(obj).map(function(e) {

View File

@@ -88,6 +88,7 @@ function compile(compilerOptions, opt_verbose) {
if (!compilerOptions) compilerOptions = {};
compilerOptions.compilation_level = 'SIMPLE_OPTIMIZATIONS';
compilerOptions.warning_level = opt_verbose ? 'VERBOSE' : 'DEFAULT';
compilerOptions.language_in = 'ECMASCRIPT5_STRICT';
compilerOptions.language_out = 'ECMASCRIPT5_STRICT';
compilerOptions.rewrite_polyfills = false;
compilerOptions.hide_warnings_for = 'node_modules';

6
package-lock.json generated
View File

@@ -1612,6 +1612,12 @@
"text-table": "^0.2.0"
}
},
"eslint-plugin-es5": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/eslint-plugin-es5/-/eslint-plugin-es5-1.4.1.tgz",
"integrity": "sha512-kktkmkF2O7pnSZYgrMiYMbt3wCKRIiXePwILv8USDG95YgP0PzhIxSIROLLKmiQQ/Z6LuhDGWTHK04gnbXBvkg==",
"dev": true
},
"eslint-scope": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.3.tgz",

View File

@@ -48,6 +48,7 @@
"chai": "^4.2.0",
"concurrently": "^4.1.2",
"eslint": "^5.13.0",
"eslint-plugin-es5": "^1.4.1",
"fs": "0.0.1-security",
"google-closure-compiler": "^20190618.0.0",
"google-closure-library": "^20190618.0.0",

View File

@@ -80,6 +80,8 @@ COMPILATION_COMMAND="java -jar $COMPILER --js='$BLOCKLY_ROOT/tests/compile/main.
--generate_exports \
--externs $BLOCKLY_ROOT/externs/svg-externs.js \
--compilation_level ADVANCED_OPTIMIZATIONS \
--language_in ECMASCRIPT5_STRICT \
--language_out ECMASCRIPT5_STRICT \
--dependency_mode=STRICT --entry_point=Main \
--js_output_file $BLOCKLY_ROOT/tests/compile/main_compressed.js"
echo "$COMPILATION_COMMAND"

View File

@@ -22,28 +22,28 @@
var assert = require('chai').assert;
var Blockly = require('../../dist/');
var xmlText = `<xml xmlns="https://developers.google.com/blockly/xml">
<block type="text_print" x="37" y="63">
<value name="TEXT">
<shadow type="text">
<field name="TEXT">Hello from Blockly!</field>
</shadow>
</value>
</block>
</xml>`;
var xmlText = '<xml xmlns="https://developers.google.com/blockly/xml">\n' +
' <block type="text_print" x="37" y="63">\n' +
' <value name="TEXT">\n' +
' <shadow type="text">\n' +
' <field name="TEXT">Hello from Blockly!</field>\n' +
' </shadow>\n' +
' </value>\n' +
' </block>\n' +
'</xml>';
suite('Test Node.js', function() {
test('Import XML', function() {
const xml = Blockly.Xml.textToDom(xmlText);
var xml = Blockly.Xml.textToDom(xmlText);
// Create workspace and import the XML
const workspace = new Blockly.Workspace();
var workspace = new Blockly.Workspace();
Blockly.Xml.domToWorkspace(xml, workspace);
});
test('Roundtrip XML', function() {
const xml = Blockly.Xml.textToDom(xmlText);
var xml = Blockly.Xml.textToDom(xmlText);
const workspace = new Blockly.Workspace();
var workspace = new Blockly.Workspace();
Blockly.Xml.domToWorkspace(xml, workspace);
var headlessXml = Blockly.Xml.workspaceToDom(workspace, true);
@@ -52,17 +52,17 @@ suite('Test Node.js', function() {
assert.equal(headlessText, xmlText, 'equal');
});
test('Generate Code', function() {
const xml = Blockly.Xml.textToDom(xmlText);
var xml = Blockly.Xml.textToDom(xmlText);
// Create workspace and import the XML
const workspace = new Blockly.Workspace();
var workspace = new Blockly.Workspace();
Blockly.Xml.domToWorkspace(xml, workspace);
// Convert code
const code = Blockly.JavaScript.workspaceToCode(workspace);
var code = Blockly.JavaScript.workspaceToCode(workspace);
// Check output
assert.equal(`window.alert('Hello from Blockly!');`, code.trim(), 'equal');
assert.equal('window.alert(\'Hello from Blockly!\');', code.trim(), 'equal');
});
});