initial commit of actions

This commit is contained in:
Dominik Polakovics Polakovics 2026-01-31 18:56:04 +01:00
commit 949ece5785
44660 changed files with 12034344 additions and 0 deletions

View file

@ -0,0 +1,18 @@
{
"extends": "eslint:recommended",
"env": {
"node": true,
"es6": true
},
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"camelcase": "error",
"eqeqeq": ["error", "smart"],
"no-implicit-globals": "error",
"no-unused-expressions": "error",
"no-var": "error",
"prefer-const": "error",
"strict": "error"
}
}

View file

@ -0,0 +1,6 @@
{
"bracketSpacing": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none"
}

View file

@ -0,0 +1,3 @@
language: node_js
node_js:
- "node"

View file

@ -0,0 +1,20 @@
Copyright (c) 2017-2019 David Graham
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1,61 @@
# eslint-plugin-i18n-text
Disallow English text in string literals.
Embedding messages in JavaScript files prevents them from being translated into
other languages. An alternative is to embed the translated text in the markup
and find it with JavaScript.
```html
<div class="js-message" data-success-message="It works!"></div>
```
```js
const el = document.querySelector('.js-message')
el.textContent = el.getAttribute('data-success-message')
```
This pattern allows the web framework that's generating the markup to use
its translation library to insert the appropriate translated text.
## Installation
You'll first need to install [ESLint](http://eslint.org):
```
$ npm install eslint --save-dev
```
Next, install `eslint-plugin-i18n-text`:
```
$ npm install eslint-plugin-i18n-text --save-dev
```
**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-i18n-text` globally.
## Usage
Add `i18n-text` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
```json
{
"plugins": [
"i18n-text"
],
"rules": {
"i18n-text/no-en": 2
}
}
```
## Development
```
npm install
npm test
```
## License
Distributed under the MIT license. See LICENSE for details.

View file

@ -0,0 +1,7 @@
'use strict'
module.exports = {
rules: {
'no-en': require('./rules/no-en')
}
}

View file

@ -0,0 +1,27 @@
{
"name": "eslint-plugin-i18n-text",
"version": "1.0.1",
"description": "Disallow English text in string literals",
"repository": "dgraham/eslint-plugin-i18n-text",
"license": "MIT",
"keywords": [
"eslint",
"eslintplugin",
"eslint-plugin"
],
"author": "David Graham",
"main": "index.js",
"scripts": {
"pretest": "eslint .",
"test": "mocha --reporter dot tests/"
},
"peerDependencies": {
"eslint": ">=5.0.0"
},
"devDependencies": {
"eslint": "^6.4.0",
"eslint-plugin-prettier": "^3.1.0",
"mocha": "^6.2.0",
"prettier": "^1.18.2"
}
}

View file

@ -0,0 +1,96 @@
'use strict'
const message = 'English text in string literals is not allowed'
function isEnglish(value) {
return typeof value === 'string' && /^[A-Z][a-z]+\s/.test(value)
}
function isConsole(node) {
return (
node.callee.type === 'MemberExpression' &&
node.callee.object.name === 'console'
)
}
function isInvariant(node) {
return node.callee.type === 'Identifier' && node.callee.name === 'invariant'
}
function isSuite(node) {
return node.callee.type === 'Identifier' && node.callee.name === 'suite'
}
function isTest(node) {
return node.callee.type === 'Identifier' && node.callee.name === 'test'
}
function isAssert(node) {
const direct =
node.callee.type === 'Identifier' && node.callee.name === 'assert'
const member =
node.callee.type === 'MemberExpression' &&
node.callee.object.name === 'assert'
return direct || member
}
module.exports = function(context) {
return {
LogicalExpression: function(node) {
if (node.right.type === 'Literal' && isEnglish(node.right.value)) {
context.report({node: node.right, message})
} else if (node.right.type === 'TemplateLiteral') {
if (node.right.quasis.some(el => isEnglish(el.value.raw))) {
context.report({node: node.right, message})
}
}
},
AssignmentExpression: function(node) {
if (node.right.type === 'Literal' && isEnglish(node.right.value)) {
context.report({node: node.right, message})
} else if (node.right.type === 'TemplateLiteral') {
if (node.right.quasis.some(el => isEnglish(el.value.raw))) {
context.report({node: node.right, message})
}
}
},
CallExpression: function(node) {
if (isConsole(node) || isInvariant(node)) return
if (isSuite(node) || isTest(node) || isAssert(node)) return
for (const arg of node.arguments) {
if (arg.type === 'Literal' && isEnglish(arg.value)) {
context.report({node: arg, message})
} else if (arg.type === 'TemplateLiteral') {
if (arg.quasis.some(el => isEnglish(el.value.raw))) {
context.report({node: arg, message})
}
}
}
},
ReturnStatement: function(node) {
if (!node.argument) return
if (node.argument.type === 'Literal' && isEnglish(node.argument.value)) {
context.report({node: node.argument, message})
} else if (node.argument.type === 'TemplateLiteral') {
if (node.argument.quasis.some(el => isEnglish(el.value.raw))) {
context.report({node: node.argument, message})
}
}
},
VariableDeclarator: function(node) {
if (!node.init) return
if (node.init.type === 'Literal' && isEnglish(node.init.value)) {
context.report({node: node.init, message})
} else if (node.init.type === 'TemplateLiteral') {
if (node.init.quasis.some(el => isEnglish(el.value.raw))) {
context.report({node: node.init, message})
}
}
}
}
}
module.exports.schema = []

View file

@ -0,0 +1,103 @@
'use strict'
const rule = require('../rules/no-en')
const RuleTester = require('eslint').RuleTester
const error = 'English text in string literals is not allowed'
const ruleTester = new RuleTester({parserOptions: {ecmaVersion: 6}})
ruleTester.run('no-en', rule, {
valid: [
'invariant(1 == 1, "Assertion message")',
'invariant(1 == 1, `Assertion message`)',
'console.debug("Debugging message")',
'console.debug(`Debugging message`)',
'console.log("Informational message")',
'console.warn("Warning message")',
'console.error("Error message")',
'throw new Error("Error message")',
'throw new Error(`Error message`)',
'var e = new Error("Error message")',
'var e = new Error(`Error message`)',
'var x = {"Object key": 42}',
'var x = {test: "Object value"}',
'x = 42',
'x = "42"',
'x = `42`',
'var x',
'var x = 42',
'var x = "42"',
'function x() { return }',
'function x() { return 42 }',
'function x() { return "42" }',
'document.addEventListener("click", function(){})',
'document.addEventListener(`click`, function(){})',
'suite("Test suite", function(){})',
'test("Test something", function(){})',
'assert.equal(1, 2, "Should be false")',
'assert(false, "Should be true")',
'assert(false, `Should be true`)'
],
invalid: [
{
code: 'el.textContent = "Some message text"',
errors: [{message: error, type: 'Literal'}]
},
{
code: 'var message = "Some message text"',
errors: [{message: error, type: 'Literal'}]
},
{
code: 'message = "Some message text"',
errors: [{message: error, type: 'Literal'}]
},
{
code: 'function x() { return "Some message text" }',
errors: [{message: error, type: 'Literal'}]
},
{
code: 'displayMessage("Some message text")',
errors: [{message: error, type: 'Literal'}]
},
{
code: 'list.push("Some message text")',
errors: [{message: error, type: 'Literal'}]
},
{
code: 'el.textContent = `Some ${x} message text`',
errors: [{message: error, type: 'TemplateLiteral'}]
},
{
code: 'el.textContent = `Some message text`',
errors: [{message: error, type: 'TemplateLiteral'}]
},
{
code: 'var message = `Some message text`',
errors: [{message: error, type: 'TemplateLiteral'}]
},
{
code: 'message = `Some message text`',
errors: [{message: error, type: 'TemplateLiteral'}]
},
{
code: 'function x() { return `Some message text` }',
errors: [{message: error, type: 'TemplateLiteral'}]
},
{
code: 'displayMessage(`Some message text`)',
errors: [{message: error, type: 'TemplateLiteral'}]
},
{
code: 'list.push(`Some message text`)',
errors: [{message: error, type: 'TemplateLiteral'}]
},
{
code: "someValue || 'Something went wrong'",
errors: [{message: error, type: 'Literal'}]
},
{
code: 'someValue || `Something went ${adjective} wrong`',
errors: [{message: error, type: 'TemplateLiteral'}]
}
]
})