Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module.exports = {
// "@typescript-eslint/no-inferrable-types": "off",
// "@typescript-eslint/no-empty-interface": "off",
// "@typescript-eslint/no-empty-function": "off",
"i18n/no-russian-character": [
"i18n/only-english-or-code": [
"error",
{
"includeIdentifier": true,
Expand All @@ -122,7 +122,7 @@ module.exports = {
{
"files": ["packages/survey-core/src/localization/*.ts"],
"rules": {
"i18n/no-russian-character": "off"
"i18n/only-english-or-code": "off"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion e2e/survey/localization.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ frameworks.forEach(framework => {
await page.evaluate(() => {
window["survey"].locale = "ru";
});
await page.hover('input[value="Далее"]'); // eslint-disable-line i18n/no-russian-character
await page.hover('input[value="Далее"]'); // eslint-disable-line i18n/only-english-or-code

await page.evaluate(() => {
window["survey"].locale = "en";
Expand Down
4 changes: 2 additions & 2 deletions e2e/survey/options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ frameworks.forEach(framework => {
await expect(requiredElement).toHaveText("*");

await page.evaluate(() => {
window["survey"].requiredText = "😱";
window["survey"].requiredText = "😱"; // eslint-disable-line i18n/only-english-or-code
window["survey"].render();
});

await expect(requiredElement).toHaveText("😱");
await expect(requiredElement).toHaveText("😱"); // eslint-disable-line i18n/only-english-or-code
});

test("set question numbers on page", async ({ page }) => {
Expand Down
6 changes: 3 additions & 3 deletions e2e/survey/preprocessTitlesAndHtml.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ frameworks.forEach((framework) => {
await initSurvey(page, framework, json);
const titleLocator = page.locator("div[id$=ariaTitle][id^=sq]");
// Check first title
let text = "A. Please type your name (*)";
let text = "A. Please type your name (*)"; // eslint-disable-line i18n/only-english-or-code
await expect(titleLocator.first()).toBeVisible();
await expect(await titleLocator.first().textContent()).toBe(text);

// Check second title
text = "B. Please type your e-mail (*)";
text = "B. Please type your e-mail (*)";// eslint-disable-line i18n/only-english-or-code
await expect(titleLocator.nth(1)).toBeVisible();
await expect(await titleLocator.nth(1).textContent()).toBe(text);

Expand All @@ -63,7 +63,7 @@ frameworks.forEach((framework) => {
await page.locator("input[value='Next']").click();

// Check third title
text = "C. wombat, please tell us what is on your mind";
text = "C. wombat, please tell us what is on your mind";// eslint-disable-line i18n/only-english-or-code
await expect(titleLocator.first()).toBeVisible();
await expect(await titleLocator.first().textContent()).toBe(text);

Expand Down
20 changes: 20 additions & 0 deletions eslint-surveyjs/eslint-plugin-i18n/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

module.exports = {
rules: {
'only-english-or-code': require('./lib/rules/only-english-or-code'),
},
rulesConfig: {
'only-english-or-code': 1,
},
configs: {
recommended: {
plugins: [
'i18n',
],
rules: {
'i18n/only-english-or-code': 'warn',
},
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

'use strict';

const define = require('../utils/define');

const lang = 'non English or Code';
const regex = /[^\x00-\x7F]+/;
module.exports = define(lang, regex);
143 changes: 143 additions & 0 deletions eslint-surveyjs/eslint-plugin-i18n/lib/utils/define.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@

module.exports = function(lang, regex) {
return {
meta: {
type: 'suggestion',

docs: {
description: `This rule helps to find out where non English characters are.`,
category: 'Best Practices',
recommended: false
},
schema: [{
type: 'object',
properties: {
includeIdentifier: {
type: 'boolean',
default: false,
},
includeComment: {
type: 'boolean',
default: false,
},
excludeArgsForFunctions: {
type: 'array',
items: {
type: 'string',
},
},
excludeModuleImports: {
type: 'boolean',
default: false,
},
},
additionalProperties: false,
}],
},
create: function(context) {
const {
includeIdentifier,
includeComment,
excludeArgsForFunctions,
excludeModuleImports,
} = context.options[0] || {};

const getExpressionName = function(node) {
const name = [];
let callee = node.callee;
if (!callee) return;
if (callee.type === 'Identifier') return callee.name;
while (callee.type === 'MemberExpression') {
if (callee.property && callee.property.type === 'Identifier') {
name.unshift(callee.property.name);
}
if (callee.object) {
if (callee.object.type === 'Identifier') {
name.unshift(callee.object.name);
return name.join('.');
} else {
callee = callee.object;
}
}
}
};

const shouldExcludeArgsForFunctions = function(node) {
if (!Array.isArray(excludeArgsForFunctions)) return false;
let parent = node.parent;
while (parent) {
if (
parent.type === 'CallExpression' &&
excludeArgsForFunctions.includes(getExpressionName(parent))
) return true;
parent = parent.parent;
}
return false;
};

const shouldExcludeModuleImports = function(node) {
if (!excludeModuleImports) return false;
let parent = node.parent;
while (parent) {
if (
['ImportDeclaration', 'ImportExpression'].includes(parent.type)
) return true;
parent = parent.parent;
}
return false;
};

const report = function(node, val) {
context.report({
node: node,
message: `Using ${lang} characters: {{ character }}`,
data: {
character: val,
},
});
};

const listeners = {
'Literal, JSXText': function(node) {
if (shouldExcludeArgsForFunctions(node)) return;

if (shouldExcludeModuleImports(node)) return;

if (typeof node.value === 'string' && regex.exec(node.raw)) {
report(node, node.raw);
}
},
'TemplateElement': function(node) {
if (shouldExcludeArgsForFunctions(node)) return;

if (shouldExcludeModuleImports(node)) return;

const v = node.value;
if (v && v.raw && regex.exec(v.raw)) {
report(node, v.raw);
}
},
};
if (includeIdentifier) {
listeners['Identifier, JSXIdentifier'] = function(node) {
if (regex.exec(node.name)) {
report(node, node.name);
}
};
}
if (includeComment) {
listeners['Program'] = function(node) {
if (node.comments && node.comments.length > 0) {
node.comments.forEach(function(node) {
if (regex.exec(node.value)) {
report(node, node.value.trim());
}
});
}
};
}

return listeners;
},
};
};
5 changes: 5 additions & 0 deletions eslint-surveyjs/eslint-plugin-i18n/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "eslint-plugin-i18n",
"version": "2.4.0",
"main": "index.js"
}
2 changes: 1 addition & 1 deletion functionalTests/questions/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ frameworks.forEach((framework) => {
});
await t.expect(questionValueInput.getAttribute("placeholder")).eql("Select...");
await changeLocale();
await t.expect(questionValueInput.getAttribute("placeholder")).eql("Bitte auswählen...");
await t.expect(questionValueInput.getAttribute("placeholder")).eql("Bitte auswählen..."); // eslint-disable-line i18n/only-english-or-code
});

test("Check popup scroll", async (t) => {
Expand Down
2 changes: 1 addition & 1 deletion functionalTests/questions/paneldynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const json = {
"Tuberculosis",
"Anesthesia Complications",
"Genetic Disorder",
"Other describe",
"Other - describe",
],
isRequired: true,
},
Expand Down
4 changes: 2 additions & 2 deletions functionalTests/survey/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// const title = "options";

// const change_question_required_text = ClientFunction(() => {
// window["survey"].requiredText = "😱";
// window["survey"].requiredText = "some"; //
// window["survey"].render();
// });

Expand Down Expand Up @@ -131,7 +131,7 @@

// await t.expect(requiredElement.textContent).eql("*");
// await change_question_required_text();
// await t.expect(requiredElement.textContent).eql("😱");
// await t.expect(requiredElement.textContent).eql("some");
// });

// test("set question numbers on page", async t => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"lint-staged": "^15.4.3",
"eslint": "^8.57.0",
"eslint-plugin-surveyjs": "file:eslint-surveyjs",
"eslint-plugin-i18n": "^2.4.0",
"eslint-plugin-i18n": "file:eslint-surveyjs/eslint-plugin-i18n",
"eslint-plugin-react": "^7.33.0",
"eslint-plugin-vue": "^9.3.0",
"get-func-name": "2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const input = { "survey-core": path.resolve(__dirname, "./entries/index.ts") };

const banner = [
"surveyjs - Survey JavaScript library v" + VERSION,
"Copyright (c) 2015-" + new Date().getFullYear() + " Devsoft Baltic OÜ - http://surveyjs.io/",
"Copyright (c) 2015-" + new Date().getFullYear() + " Devsoft Baltic OÜ - http://surveyjs.io/", // eslint-disable-line i18n/only-english-or-code
"License: MIT (http://www.opensource.org/licenses/mit-license.php)",
].join("\n");

Expand Down
2 changes: 2 additions & 0 deletions packages/survey-core/src/question_custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface ICustomQuestionTypeConfiguration {
* Set this property to `false` if your custom question type is used only to customize Property Grid content and is not meant for a survey.
*/
showInToolbox?: boolean;
/* eslint-disable */
/**
* A default title for questions created with this question type. Survey authors can change the default title in the JSON object or in Survey Creator's Property Grid.
*
Expand All @@ -89,6 +90,7 @@ export interface ICustomQuestionTypeConfiguration {
* });
* ```
*/
/* eslint-enable */
defaultQuestionTitle?: any;
/**
* An array of property names to inherit from a base question or a Boolean value that specifies whether or not to inherit all properties.
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/tests/basetests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ QUnit.test("base.resetPropertyValue() for localization string, #2, bug#7388", fu
survey.completeText = "test de";
assert.equal(survey.completeText, "test de", "set value de");
survey.resetPropertyValue("completeText");
assert.equal(survey.completeText, "Abschließen", "default value de");
assert.equal(survey.completeText, "Abschließen", "default value de"); // eslint-disable-line i18n/only-english-or-code
survey.locale = "";
assert.equal(survey.completeText, "Complete", "default value en");
});
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/tests/choicesRestfultests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1969,8 +1969,8 @@ function getCountries(): any {
alpha3_code: "AFG",
},
{
name: "Åland Islands",
locName: { en: "Åland Islands" },
name: "Åland Islands", // eslint-disable-line i18n/only-english-or-code
locName: { en: "Åland Islands" }, // eslint-disable-line i18n/only-english-or-code
alpha2_code: "AX",
alpha3_code: "ALA",
},
Expand Down
8 changes: 4 additions & 4 deletions packages/survey-core/tests/components/actionbartests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ QUnit.test("Action title", (assert) => {
assert.equal(action1.tooltip, "Preview", "take tooltip from en localization");
survey.locale = "de";
assert.equal(action1.getLocale(), "de", "locale de");
assert.equal(action1.locTitle.text, "Alles auswählen", "take text from de localization");
assert.equal(action1.title, "Alles auswählen", "Update action title de localization");
assert.equal(action1.locTitle.text, "Alles auswählen", "take text from de localization"); // eslint-disable-line i18n/only-english-or-code
assert.equal(action1.title, "Alles auswählen", "Update action title de localization"); // eslint-disable-line i18n/only-english-or-code
assert.equal(action1.tooltip, "Vorschau", "take tooltip from de localization");
survey.locale = "";
});
Expand All @@ -227,8 +227,8 @@ QUnit.test("Action title in list model", (assert) => {
assert.equal(action1.tooltip, "Preview", "take tooltip from en localization");
survey.locale = "de";
assert.equal(action1.getLocale(), "de");
assert.equal(action1.locTitle.text, "Alles auswählen", "take text from de localization");
assert.equal(action1.title, "Alles auswählen", "Update action title de localization");
assert.equal(action1.locTitle.text, "Alles auswählen", "take text from de localization"); // eslint-disable-line i18n/only-english-or-code
assert.equal(action1.title, "Alles auswählen", "Update action title de localization"); // eslint-disable-line i18n/only-english-or-code
assert.equal(action1.tooltip, "Vorschau", "take tooltip from de localization");
survey.locale = "";
});
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/tests/dropdown_list_model_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ QUnit.test("DropdownListModel buttons", (assert) => {
assert.equal(clearButton.enabled, true, "clearButton enabled #4");
assert.equal(clearButton.visible, true, "clearButton visible #4");

assert.equal(chevronButton.locTitle.text, "Auswählen", "chevronButton title #4");
assert.equal(chevronButton.locTitle.text, "Auswählen", "chevronButton title #4"); // eslint-disable-line i18n/only-english-or-code
assert.equal(chevronButton.enabled, true, "chevronButton enabled #4");
assert.equal(chevronButton.visible, true, "chevronButton visible #4");

Expand Down
6 changes: 3 additions & 3 deletions packages/survey-core/tests/helperstests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ QUnit.test("isTwoValueEquals, strings: trim and caseSensitive", function(assert)
settings.comparator.caseSensitive = false;
});
QUnit.test("isTwoValueEquals, strings: settings.normalizeTextCallback", function(assert) {
assert.equal(Helpers.isTwoValueEquals("Brouillé", "Brouille"), false, "#1");
assert.equal(Helpers.isTwoValueEquals("Brouillé", "Brouille"), false, "#1"); // eslint-disable-line i18n/only-english-or-code
settings.comparator.normalizeTextCallback = (str: string, reason: string): string => {
return reason === "compare" ? str.normalize("NFD").replace(/[\u0300-\u036f]/g, "") : str;
};
assert.equal(Helpers.isTwoValueEquals("Brouillé", "Brouille"), true, "#2");
assert.equal(Helpers.isTwoValueEquals("Brouillé", "Brouille"), true, "#2"); // eslint-disable-line i18n/only-english-or-code
settings.comparator.normalizeTextCallback = (str: string, reason: string): string => { return str; };
});

Expand Down Expand Up @@ -499,7 +499,7 @@ QUnit.test("Check compareStrings function", function(assert) {
settings.comparator.normalizeTextCallback = (str: string, reason: string): string => {
return reason === "compare" ? str.normalize("NFD").replace(/[\u0300-\u036f]/g, "") : str;
};
assert.equal(Helpers.compareStrings("Brouillé", "Brouille"), 0, "#17");
assert.equal(Helpers.compareStrings("Brouillé", "Brouille"), 0, "#17"); // eslint-disable-line i18n/only-english-or-code
settings.comparator.normalizeTextCallback = (str: string, reason: string): string => { return str; };
});
QUnit.test("getUnbindValue function", function(assert) {
Expand Down
Loading