chore: use prettier instead of clang-format (#7014)

* chore: add and configure prettier

* chore: remove clang-format

* chore: remove clang-format config

* chore: lint additional ts files

* chore: fix lint errors in blocks

* chore: add prettier-ignore where needed

* chore: ignore js blocks when formatting

* chore: fix playground html syntax

* chore: fix yaml spacing from merge

* chore: convert text blocks to use arrow functions

* chore: format everything with prettier

* chore: fix lint unused imports in blocks
This commit is contained in:
Maribeth Bottorff
2023-05-10 16:01:39 -07:00
committed by GitHub
parent af991f5e1b
commit 88ff901a72
425 changed files with 29170 additions and 21169 deletions

View File

@@ -7,16 +7,27 @@
goog.declareModuleId('Blockly.test.fieldTextInput');
import * as Blockly from '../../build/src/core/blockly.js';
import {assertFieldValue, runConstructorSuiteTests, runFromJsonSuiteTests, runSetValueTests} from './test_helpers/fields.js';
import {createTestBlock, defineRowBlock} from './test_helpers/block_definitions.js';
import {sharedTestSetup, sharedTestTeardown, workspaceTeardown} from './test_helpers/setup_teardown.js';
import {
assertFieldValue,
runConstructorSuiteTests,
runFromJsonSuiteTests,
runSetValueTests,
} from './test_helpers/fields.js';
import {
createTestBlock,
defineRowBlock,
} from './test_helpers/block_definitions.js';
import {
sharedTestSetup,
sharedTestTeardown,
workspaceTeardown,
} from './test_helpers/setup_teardown.js';
suite('Text Input Fields', function() {
setup(function() {
suite('Text Input Fields', function () {
setup(function () {
sharedTestSetup.call(this);
});
teardown(function() {
teardown(function () {
sharedTestTeardown.call(this);
});
/**
@@ -39,7 +50,7 @@ suite('Text Input Fields', function() {
{title: 'Number (Falsy)', value: 0, expectedValue: '0'},
{title: 'NaN', value: NaN, expectedValue: 'NaN'},
];
const addArgsAndJson = function(testCase) {
const addArgsAndJson = function (testCase) {
testCase.args = [testCase.value];
testCase.json = {'text': testCase.value};
};
@@ -55,7 +66,7 @@ suite('Text Input Fields', function() {
* Asserts that the field property values are set to default.
* @param {!Blockly.FieldTextInput} field The field to check.
*/
const assertFieldDefault = function(field) {
const assertFieldDefault = function (field) {
assertFieldValue(field, defaultFieldValue);
};
/**
@@ -63,39 +74,53 @@ suite('Text Input Fields', function() {
* @param {!Blockly.FieldTextInput} field The field to check.
* @param {!FieldValueTestCase} testCase The test case.
*/
const validTestCaseAssertField = function(field, testCase) {
const validTestCaseAssertField = function (field, testCase) {
assertFieldValue(field, testCase.expectedValue);
};
runConstructorSuiteTests(
Blockly.FieldTextInput, validValueTestCases, invalidValueTestCases,
validTestCaseAssertField, assertFieldDefault);
Blockly.FieldTextInput,
validValueTestCases,
invalidValueTestCases,
validTestCaseAssertField,
assertFieldDefault
);
runFromJsonSuiteTests(
Blockly.FieldTextInput, validValueTestCases, invalidValueTestCases,
validTestCaseAssertField, assertFieldDefault);
Blockly.FieldTextInput,
validValueTestCases,
invalidValueTestCases,
validTestCaseAssertField,
assertFieldDefault
);
suite('setValue', function() {
suite('Empty -> New Value', function() {
setup(function() {
suite('setValue', function () {
suite('Empty -> New Value', function () {
setup(function () {
this.field = new Blockly.FieldTextInput();
});
runSetValueTests(
validValueTestCases, invalidValueTestCases, defaultFieldValue);
test('With source block', function() {
validValueTestCases,
invalidValueTestCases,
defaultFieldValue
);
test('With source block', function () {
this.field.setSourceBlock(createTestBlock());
this.field.setValue('value');
assertFieldValue(this.field, 'value');
});
});
suite('Value -> New Value', function() {
suite('Value -> New Value', function () {
const initialValue = 'oldValue';
setup(function() {
setup(function () {
this.field = new Blockly.FieldTextInput(initialValue);
});
runSetValueTests(
validValueTestCases, invalidValueTestCases, initialValue);
test('With source block', function() {
validValueTestCases,
invalidValueTestCases,
initialValue
);
test('With source block', function () {
this.field.setSourceBlock(createTestBlock());
this.field.setValue('value');
assertFieldValue(this.field, 'value');
@@ -103,46 +128,58 @@ suite('Text Input Fields', function() {
});
});
suite('Validators', function() {
setup(function() {
suite('Validators', function () {
setup(function () {
this.field = new Blockly.FieldTextInput('value');
this.field.htmlInput_ = document.createElement('input');
this.field.htmlInput_.setAttribute('data-old-value', 'value');
this.field.htmlInput_.setAttribute('data-untyped-default-value', 'value');
this.stub = sinon.stub(this.field, 'resizeEditor_');
});
teardown(function() {
teardown(function () {
sinon.restore();
});
const testSuites = [
{title: 'Null Validator',
validator:
function() {
return null;
},
value: 'newValue', expectedValue: 'value'},
{title: 'Remove \'a\' Validator',
validator:
function(newValue) {
return newValue.replace(/a/g, '');
},
value: 'bbbaaa', expectedValue: 'bbb'},
{title: 'Returns Undefined Validator', validator: function() {},
value: 'newValue', expectedValue: 'newValue', expectedText: 'newValue'},
{
title: 'Null Validator',
validator: function () {
return null;
},
value: 'newValue',
expectedValue: 'value',
},
{
title: "Remove 'a' Validator",
validator: function (newValue) {
return newValue.replace(/a/g, '');
},
value: 'bbbaaa',
expectedValue: 'bbb',
},
{
title: 'Returns Undefined Validator',
validator: function () {},
value: 'newValue',
expectedValue: 'newValue',
expectedText: 'newValue',
},
];
testSuites.forEach(function(suiteInfo) {
suite(suiteInfo.title, function() {
setup(function() {
testSuites.forEach(function (suiteInfo) {
suite(suiteInfo.title, function () {
setup(function () {
this.field.setValidator(suiteInfo.validator);
});
test('When Editing', function() {
test('When Editing', function () {
this.field.isBeingEdited_ = true;
this.field.htmlInput_.value = suiteInfo.value;
this.field.onHtmlInputChange_(null);
assertFieldValue(
this.field, suiteInfo.expectedValue, suiteInfo.value);
this.field,
suiteInfo.expectedValue,
suiteInfo.value
);
});
test('When Not Editing', function() {
test('When Not Editing', function () {
this.field.setValue(suiteInfo.value);
assertFieldValue(this.field, suiteInfo.expectedValue);
});
@@ -150,29 +187,29 @@ suite('Text Input Fields', function() {
});
});
suite('Customization', function() {
suite('Spellcheck', function() {
setup(function() {
this.prepField = function(field) {
suite('Customization', function () {
suite('Spellcheck', function () {
setup(function () {
this.prepField = function (field) {
const workspace = {
getScale: function() {
getScale: function () {
return 1;
},
getRenderer: function() {
getRenderer: function () {
return {
getClassName: function() {
getClassName: function () {
return '';
},
};
},
getTheme: function() {
getTheme: function () {
return {
getClassName: function() {
getClassName: function () {
return '';
},
};
},
markFocused: function() {},
markFocused: function () {},
options: {},
};
field.sourceBlock_ = {
@@ -189,41 +226,43 @@ suite('Text Input Fields', function() {
this.stub = sinon.stub(field, 'resizeEditor_');
};
this.assertSpellcheck = function(field, value) {
this.assertSpellcheck = function (field, value) {
this.prepField(field);
field.showEditor_();
chai.assert.equal(field.htmlInput_.getAttribute('spellcheck'),
value.toString());
chai.assert.equal(
field.htmlInput_.getAttribute('spellcheck'),
value.toString()
);
};
});
teardown(function() {
teardown(function () {
if (this.stub) {
this.stub.restore();
}
});
test('Default', function() {
test('Default', function () {
const field = new Blockly.FieldTextInput('test');
this.assertSpellcheck(field, true);
});
test('JS Constructor', function() {
test('JS Constructor', function () {
const field = new Blockly.FieldTextInput('test', null, {
spellcheck: false,
});
this.assertSpellcheck(field, false);
});
test('JSON Definition', function() {
test('JSON Definition', function () {
const field = Blockly.FieldTextInput.fromJson({
text: 'test',
spellcheck: false,
});
this.assertSpellcheck(field, false);
});
test('setSpellcheck Editor Hidden', function() {
test('setSpellcheck Editor Hidden', function () {
const field = new Blockly.FieldTextInput('test');
field.setSpellcheck(false);
this.assertSpellcheck(field, false);
});
test('setSpellcheck Editor Shown', function() {
test('setSpellcheck Editor Shown', function () {
const field = new Blockly.FieldTextInput('test');
this.prepField(field);
field.showEditor_();
@@ -233,8 +272,8 @@ suite('Text Input Fields', function() {
});
});
suite('Serialization', function() {
setup(function() {
suite('Serialization', function () {
setup(function () {
this.workspace = new Blockly.Workspace();
defineRowBlock();
@@ -247,11 +286,11 @@ suite('Text Input Fields', function() {
};
});
teardown(function() {
teardown(function () {
workspaceTeardown.call(this, this.workspace);
});
test('Simple', function() {
test('Simple', function () {
this.assertValue('test text');
});
});