Skip to content

Commit

Permalink
eslint: used @Stylistic rules
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jun 3, 2024
1 parent 2ceb5bd commit e6c29ca
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coding-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: npm install
- run: npx eslint src/assets/netteForms.js
- run: npx eslint
36 changes: 25 additions & 11 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
import globals from 'globals';
import pluginJs from '@eslint/js';
import stylistic from '@stylistic/eslint-plugin';

export default [
pluginJs.configs.recommended,
{
ignores: ['**/*.min.js'],
ignores: ['*/*', '!src/*', '!tests/*', '**/*.min.js'],
},

pluginJs.configs.recommended,

stylistic.configs.customize({
indent: 'tab',
braceStyle: '1tbs',
arrowParens: true,
semi: true,
jsx: false,
}),

{
languageOptions: {
ecmaVersion: 2021,
globals: {
...globals.browser,
'Tracy': 'writeable',
'define': 'readable',
'module': 'readable',
...globals.jasmine,
Nette: 'readable',
Tracy: 'writeable',
define: 'readable',
module: 'readable',
},
},
plugins: {
'@stylistic': stylistic,
},
rules: {
indent: ['error', 'tab'],
quotes: ['error', 'single'],
semi: ['error', 'always'],
'func-style': ['error', 'declaration', {'allowArrowFunctions': true}],
'@stylistic/no-multiple-empty-lines': ['error', { max: 2, maxEOF: 0 }],
'@stylistic/new-parens': ['error', 'never'],
'@stylistic/padded-blocks': 'off',
'func-style': ['error', 'declaration', { allowArrowFunctions: true }],
'prefer-arrow-callback': ['error'],
'arrow-parens': ['error'],
'arrow-spacing': ['error'],
'no-var': ['error'],
},
},
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
"url": "git+https://github.com/nette/forms.git"
},
"devDependencies": {
"@eslint/js": "^9.1.1",
"eslint": "^9.1.1",
"globals": "^15.1.0"
"@eslint/js": "^9.4.0",
"@stylistic/eslint-plugin": "^2.1.0",
"eslint": "^9.4.0",
"globals": "^15.3.0"
}
}
28 changes: 14 additions & 14 deletions src/assets/netteForms.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**!
/*!
* NetteForms - simple form validation.
*
* This file is part of the Nette Framework (https://nette.org)
Expand Down Expand Up @@ -33,7 +33,7 @@
const Nette = {};
let preventFiltering = {};
let formToggles = {};
let toggleListeners = new window.WeakMap();
let toggleListeners = new window.WeakMap;

Nette.formErrors = [];
Nette.version = '3.3.0';
Expand Down Expand Up @@ -129,7 +129,7 @@
}
if (filter && preventFiltering[elem.name] === undefined) {
preventFiltering[elem.name] = true;
let ref = {value: val};
let ref = { value: val };
Nette.validateControl(elem, null, true, ref);
val = ref.value;
delete preventFiltering[elem.name];
Expand All @@ -149,7 +149,7 @@
*/
Nette.validateControl = function (elem, rules, onlyCheck = false, value = null, emptyOptional = null) {
rules ??= JSON.parse(elem.getAttribute('data-nette-rules') ?? '[]');
value ??= {value: Nette.getEffectiveValue(elem)};
value ??= { value: Nette.getEffectiveValue(elem) };
emptyOptional ??= !Nette.validateRule(elem, ':filled', null, value);

for (let rule of rules) {
Expand Down Expand Up @@ -185,7 +185,7 @@
let arr = Array.isArray(rule.arg) ? rule.arg : [rule.arg],
message = rule.msg.replace(
/%(value|\d+)/g,
(foo, m) => Nette.getValue(m === 'value' ? curElem : elem.form.elements.namedItem(arr[m].control))
(foo, m) => Nette.getValue(m === 'value' ? curElem : elem.form.elements.namedItem(arr[m].control)),
);
Nette.addError(curElem, message);
}
Expand Down Expand Up @@ -265,7 +265,7 @@
Nette.addError = function (elem, message) {
Nette.formErrors.push({
element: elem,
message: message
message: message,
});
};

Expand Down Expand Up @@ -343,7 +343,7 @@
return op === ':filled';
}

value ??= {value: Nette.getEffectiveValue(elem, true)};
value ??= { value: Nette.getEffectiveValue(elem, true) };

let method = op.charAt(0) === ':' ? op.substring(1) : op;
method = method.replace('::', '_').replaceAll('\\', '');
Expand Down Expand Up @@ -482,7 +482,7 @@
return false;
},

'float': function (elem, arg, val, newValue) {
float: function (elem, arg, val, newValue) {
val = val.replace(/ +/g, '').replace(/,/g, '.');
if ((/^-?[0-9]*\.?[0-9]+$/).test(val)) {
newValue.value = parseFloat(val);
Expand Down Expand Up @@ -535,9 +535,9 @@
return Nette.validators.mimeType(elem, arg ?? ['image/gif', 'image/png', 'image/jpeg', 'image/webp'], val);
},

'static': function (elem, arg) {
static: function (elem, arg) {
return arg;
}
},
};


Expand Down Expand Up @@ -572,7 +572,7 @@
*/
Nette.toggleControl = function (elem, rules, success, firsttime, value = null, emptyOptional = null) {
rules ??= JSON.parse(elem.getAttribute('data-nette-rules') ?? '[]');
value ??= {value: Nette.getEffectiveValue(elem)};
value ??= { value: Nette.getEffectiveValue(elem) };
emptyOptional ??= !Nette.validateRule(elem, ':filled', null, value);

let has = false,
Expand Down Expand Up @@ -617,7 +617,7 @@
});
}
for (let id in rule.toggle ?? []) {
formToggles[id] ??= {elem: elem};
formToggles[id] ??= { elem: elem };
formToggles[id].state ||= rule.toggle[id] ? curSuccess : !curSuccess;
}
}
Expand Down Expand Up @@ -708,7 +708,7 @@
document.body.addEventListener('click', (e) => {
let target = e.target;
while (target) {
if (target.form && target.type in {submit: 1, image: 1}) {
if (target.form && target.type in { submit: 1, image: 1 }) {
target.form['nette-submittedBy'] = target;
break;
}
Expand All @@ -734,7 +734,7 @@
return res.replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
};

Nette.webalizeTable = {\u00e1: 'a', \u00e4: 'a', \u010d: 'c', \u010f: 'd', \u00e9: 'e', \u011b: 'e', \u00ed: 'i', \u013e: 'l', \u0148: 'n', \u00f3: 'o', \u00f4: 'o', \u0159: 'r', \u0161: 's', \u0165: 't', \u00fa: 'u', \u016f: 'u', \u00fd: 'y', \u017e: 'z'};
Nette.webalizeTable = { \u00e1: 'a', \u00e4: 'a', \u010d: 'c', \u010f: 'd', \u00e9: 'e', \u011b: 'e', \u00ed: 'i', \u013e: 'l', \u0148: 'n', \u00f3: 'o', \u00f4: 'o', \u0159: 'r', \u0161: 's', \u0165: 't', \u00fa: 'u', \u016f: 'u', \u00fd: 'y', \u017e: 'z' };

return Nette;
}));
4 changes: 2 additions & 2 deletions tests/netteForms/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module.exports = function(config) {
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
browsers: ['ChromeHeadless'],
files: [
'../../src/assets/netteForms.js',
'spec/*Spec.js'
'spec/*Spec.js',
],
autoWatch: false,
singleRun: true,
Expand Down
2 changes: 1 addition & 1 deletion tests/netteForms/spec/Nette.validatorsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('Nette.validators', () => {


it('url', () => {
let v = {value: null};
let v = { value: null };
expect(Nette.validators.url(null, null, '', v)).toBe(false);
expect(Nette.validators.url(null, null, 'hello', v)).toBe(true);
expect(v.value).toBe('https://hello');
Expand Down

0 comments on commit e6c29ca

Please sign in to comment.