From 5c617e9de1ac3f99aa2671134ce5d4d43907f1ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr> Date: Mon, 3 Jan 2022 10:55:10 +0100 Subject: [PATCH] [ivette/lint] add rule to restrict '+' operands --- ivette/.eslintrc.js | 2 ++ ivette/src/dome/renderer/layout/forms.tsx | 6 +++--- ivette/src/frama-c/plugins/eva/probes.ts | 2 +- ivette/src/frama-c/server.ts | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ivette/.eslintrc.js b/ivette/.eslintrc.js index 9158c04e76f..377b7766eed 100644 --- a/ivette/.eslintrc.js +++ b/ivette/.eslintrc.js @@ -67,6 +67,8 @@ module.exports = { "curly": "off", // Do not specify position for single commands "nonblock-statement-body-position": "off", + // Requires '+' to be applied on 2 numbers or 2 strings only + "@typescript-eslint/restrict-plus-operands": "error", // Allow ++/-- operators only in for-loops "no-plusplus": ["error", { "allowForLoopAfterthoughts": true }], // Force code to 80 columns, but for trailing comments diff --git a/ivette/src/dome/renderer/layout/forms.tsx b/ivette/src/dome/renderer/layout/forms.tsx index 79d96f2f1e7..1bd3c06935a 100644 --- a/ivette/src/dome/renderer/layout/forms.tsx +++ b/ivette/src/dome/renderer/layout/forms.tsx @@ -73,7 +73,7 @@ export function validate<A>( if (r === undefined || r === true) return undefined; return r; } catch (err) { - return '' + err || false; + return `${err}`; } } return undefined; @@ -250,7 +250,7 @@ export function useFilter<A, B>( } } catch (err) { setLocalValue(newValue); - setLocalError(newError || err ? '' + err : 'Invalid value'); + setLocalError(newError || err ? `${err}` : 'Invalid value'); setDangling(true); } }, [output, setState, setLocalValue, setLocalError], @@ -262,7 +262,7 @@ export function useFilter<A, B>( try { return [input(value), error, update]; } catch (err) { - return [localValue, err ? '' + err : 'Invalid input', update]; + return [localValue, err ? `${err}` : 'Invalid input', update]; } } diff --git a/ivette/src/frama-c/plugins/eva/probes.ts b/ivette/src/frama-c/plugins/eva/probes.ts index cf1dd2709e6..38c4497ead8 100644 --- a/ivette/src/frama-c/plugins/eva/probes.ts +++ b/ivette/src/frama-c/plugins/eva/probes.ts @@ -52,7 +52,7 @@ function newLabel() { La = Ka; Lk++; } - return k > 0 ? lbl + k : lbl; + return k > 0 ? `${lbl}${k}` : lbl; } /* --------------------------------------------------------------------------*/ diff --git a/ivette/src/frama-c/server.ts b/ivette/src/frama-c/server.ts index 8c84ddcfb27..f4039c19e23 100644 --- a/ivette/src/frama-c/server.ts +++ b/ivette/src/frama-c/server.ts @@ -392,7 +392,7 @@ async function _launch() { buffer.clear(); buffer.append('$', command); - const size = params.reduce((n: any, p: any) => n + p.length, 0); + const size = params.reduce((n, p) => n + p.length, 0); if (size < 40) { buffer.append('', ...params); } else { -- GitLab