diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 5655eeea..cf1dd7c9 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -64,6 +64,13 @@ jobs: # leak sanitizer sometimes crashes - run: cd /root/vitastor/build && ASAN_OPTIONS=detect_leaks=0 make -j16 test + npm_lint: + runs-on: ubuntu-latest + needs: build + container: ${{env.TEST_IMAGE}}:${{github.sha}} + steps: + - run: cd /root/vitastor/mon && npm run lint + test_add_osd: runs-on: ubuntu-latest needs: build diff --git a/mon/.eslintrc.js b/mon/.eslintrc.js new file mode 100644 index 00000000..385082bb --- /dev/null +++ b/mon/.eslintrc.js @@ -0,0 +1,55 @@ +module.exports = { + "env": { + "es6": true, + "node": true + }, + "extends": [ + "eslint:recommended", + "plugin:node/recommended" + ], + "parserOptions": { + "ecmaVersion": 2020 + }, + "plugins": [ + ], + "rules": { + "indent": [ + "error", + 4 + ], + "brace-style": [ + "error", + "allman", + { "allowSingleLine": true } + ], + "linebreak-style": [ + "error", + "unix" + ], + "semi": [ + "error", + "always" + ], + "require-atomic-updates": [ + "off" + ], + "no-useless-escape": [ + "off" + ], + "no-control-regex": [ + "off" + ], + "no-unused-vars": [ + "off" + ], + "no-empty": [ + "off" + ], + "no-process-exit": [ + "off" + ], + "node/shebang": [ + "off" + ] + } +}; diff --git a/mon/dsl_pgs.js b/mon/dsl_pgs.js index cbf87d6f..f1813df4 100644 --- a/mon/dsl_pgs.js +++ b/mon/dsl_pgs.js @@ -152,6 +152,7 @@ function parse_pg_dsl(text) else if (rule[2] === '(') { rule[2] = []; + // eslint-disable-next-line no-constant-condition while (true) { if (i > tokens.length-1) diff --git a/mon/mon.js b/mon/mon.js index c72cd54f..244785f0 100644 --- a/mon/mon.js +++ b/mon/mon.js @@ -747,6 +747,7 @@ class Mon this.save_last_clean_running = true; // last_clean_pgs is used to avoid extra data move when observing a series of changes in the cluster const new_clean_pgs = { items: {} }; + // eslint-disable-next-line indent next_pool: for (const pool_id in this.state.config.pools) { @@ -829,6 +830,7 @@ class Mon async become_master() { const state = { ...this.get_mon_state(), id: ''+this.etcd_lease_id }; + // eslint-disable-next-line no-constant-condition while (1) { const res = await this.etcd_call('/kv/txn', { @@ -1316,7 +1318,7 @@ class Mon for (const k in rules) { if (!levels[k] || typeof rules[k] !== 'string' && - (!rules[k] instanceof Array || + (!(rules[k] instanceof Array) || rules[k].filter(s => typeof s !== 'string' && typeof s !== 'number').length > 0)) { if (warn) diff --git a/mon/package.json b/mon/package.json index 550d0148..16cd0c96 100644 --- a/mon/package.json +++ b/mon/package.json @@ -11,5 +11,15 @@ "dependencies": { "sprintf-js": "^1.1.2", "ws": "^7.2.5" + }, + "devDependencies": { + "eslint": "^8.0.0", + "eslint-plugin-node": "^11.1.0" + }, + "engines": { + "node": ">=12.0.0" + }, + "scripts": { + "lint": "eslint *.js" } } diff --git a/mon/simple-offsets.js b/mon/simple-offsets.js index e2ae667d..72a5b6de 100644 --- a/mon/simple-offsets.js +++ b/mon/simple-offsets.js @@ -38,7 +38,7 @@ async function run() const st = await fs.stat(options.device); options.device_block_size = st.blksize; if (st.isBlockDevice()) - device_size = Number(await system("/sbin/blockdev --getsize64 "+options.device)) + device_size = Number(await system("/sbin/blockdev --getsize64 "+options.device)); else device_size = st.size; } diff --git a/mon/test-optimize.js b/mon/test-optimize.js index 34b357aa..0ae931aa 100644 --- a/mon/test-optimize.js +++ b/mon/test-optimize.js @@ -20,7 +20,7 @@ const osd_tree = { }, 500: { 4: 3.58498, -// 8: 3.58589, + /*8: 3.58589,*/ 9: 3.63869, }, 600: { diff --git a/rpm/vitastor-el7.spec b/rpm/vitastor-el7.spec index d55be76e..e808a8ea 100644 --- a/rpm/vitastor-el7.spec +++ b/rpm/vitastor-el7.spec @@ -104,7 +104,7 @@ rm -rf $RPM_BUILD_ROOT %make_install . /opt/rh/rh-nodejs12/enable cd mon -npm install +npm install --production cd .. mkdir -p %buildroot/usr/lib/vitastor cp -r mon %buildroot/usr/lib/vitastor diff --git a/rpm/vitastor-el8.spec b/rpm/vitastor-el8.spec index 8f74037d..a7323eb2 100644 --- a/rpm/vitastor-el8.spec +++ b/rpm/vitastor-el8.spec @@ -101,7 +101,7 @@ Vitastor fio drivers for benchmarking. rm -rf $RPM_BUILD_ROOT %make_install cd mon -npm install +npm install --production cd .. mkdir -p %buildroot/usr/lib/vitastor cp -r mon %buildroot/usr/lib/vitastor diff --git a/rpm/vitastor-el9.spec b/rpm/vitastor-el9.spec index f6c5f06f..859ce169 100644 --- a/rpm/vitastor-el9.spec +++ b/rpm/vitastor-el9.spec @@ -94,7 +94,7 @@ Vitastor fio drivers for benchmarking. rm -rf $RPM_BUILD_ROOT %cmake_install cd mon -npm install +npm install --production cd .. mkdir -p %buildroot/usr/lib/vitastor cp -r mon %buildroot/usr/lib/vitastor