From c86b813519789e39efb192d373554b4e56b4c3bc Mon Sep 17 00:00:00 2001 From: Yulong Wang Date: Fri, 6 Aug 2021 19:35:43 -0700 Subject: [PATCH] [js] resolve CodeQL warnings for force strict mode (#8645) --- js/.eslintrc.js | 5 +++++ js/common/webpack.config.js | 5 +++++ js/react_native/babel.config.js | 2 ++ js/react_native/example/babel.config.js | 2 ++ js/react_native/example/metro.config.js | 2 ++ js/react_native/scripts/bootstrap.js | 2 ++ js/web/karma.conf.js | 2 ++ js/web/test/e2e/browser-test-wasm-no-threads.js | 2 ++ js/web/test/e2e/browser-test-wasm-path-override-filename.js | 2 ++ js/web/test/e2e/browser-test-wasm-path-override-prefix.js | 2 ++ js/web/test/e2e/browser-test-wasm.js | 2 ++ js/web/test/e2e/browser-test-webgl.js | 2 ++ js/web/test/e2e/common.js | 2 ++ js/web/test/e2e/karma.conf.js | 2 ++ js/web/test/e2e/node-test-main-no-threads.js | 2 ++ js/web/test/e2e/node-test-main.js | 2 ++ js/web/test/e2e/node-test-wasm-path-override-filename.js | 2 ++ js/web/test/e2e/node-test-wasm-path-override-prefix.js | 2 ++ js/web/test/e2e/run.js | 2 ++ js/web/test/e2e/simple-http-server.js | 2 ++ js/web/test/unittests/index.ts | 2 ++ js/web/webpack.config.js | 2 ++ onnxruntime/test/wasm/dump-test-result-in-nodejs.js | 2 ++ samples/nodejs/01_basic-usage/index.js | 1 + samples/nodejs/02_create-tensor/index.js | 1 + samples/nodejs/04_create-inference-session/index.js | 1 + 26 files changed, 55 insertions(+) diff --git a/js/.eslintrc.js b/js/.eslintrc.js index f41c39aa52012..278ffce6a5152 100644 --- a/js/.eslintrc.js +++ b/js/.eslintrc.js @@ -1,3 +1,8 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +'use strict'; + module.exports = { root: true, ignorePatterns: ['**/*.js', 'node_modules/', 'types/', 'dist/'], diff --git a/js/common/webpack.config.js b/js/common/webpack.config.js index efe9596806e5e..d35f90b525a30 100644 --- a/js/common/webpack.config.js +++ b/js/common/webpack.config.js @@ -1,3 +1,8 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +'use strict'; + const path = require('path'); const webpack = require('webpack'); const TerserPlugin = require("terser-webpack-plugin"); diff --git a/js/react_native/babel.config.js b/js/react_native/babel.config.js index f842b77fcfb8b..e2240f1f51f8b 100644 --- a/js/react_native/babel.config.js +++ b/js/react_native/babel.config.js @@ -1,3 +1,5 @@ +'use strict'; + module.exports = { presets: ['module:metro-react-native-babel-preset'], }; diff --git a/js/react_native/example/babel.config.js b/js/react_native/example/babel.config.js index db64a007b32e7..96ef381f7825d 100644 --- a/js/react_native/example/babel.config.js +++ b/js/react_native/example/babel.config.js @@ -1,3 +1,5 @@ +'use strict'; + const path = require('path'); const pak = require('../package.json'); diff --git a/js/react_native/example/metro.config.js b/js/react_native/example/metro.config.js index d1f468ab03388..befddbf0934f2 100644 --- a/js/react_native/example/metro.config.js +++ b/js/react_native/example/metro.config.js @@ -1,3 +1,5 @@ +'use strict'; + const path = require('path'); const blacklist = require('metro-config/src/defaults/blacklist'); const escape = require('escape-string-regexp'); diff --git a/js/react_native/scripts/bootstrap.js b/js/react_native/scripts/bootstrap.js index 6ba193d30aef1..34650de57d4c6 100644 --- a/js/react_native/scripts/bootstrap.js +++ b/js/react_native/scripts/bootstrap.js @@ -1,3 +1,5 @@ +'use strict'; + const path = require('path'); const child_process = require('child_process'); diff --git a/js/web/karma.conf.js b/js/web/karma.conf.js index 2cc56cfe043b6..5dc3943a7d618 100644 --- a/js/web/karma.conf.js +++ b/js/web/karma.conf.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +'use strict'; + const bundleMode = require('minimist')(process.argv)['bundle-mode'] || 'dev'; // 'dev'|'perf'|undefined; const karmaPlugins = require('minimist')(process.argv)['karma-plugins'] || undefined; const timeoutMocha = require('minimist')(process.argv)['timeout-mocha'] || 60000; diff --git a/js/web/test/e2e/browser-test-wasm-no-threads.js b/js/web/test/e2e/browser-test-wasm-no-threads.js index 6ed7193b405b5..f86d6c7dbc1a0 100644 --- a/js/web/test/e2e/browser-test-wasm-no-threads.js +++ b/js/web/test/e2e/browser-test-wasm-no-threads.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +'use strict'; + it('Browser E2E testing - WebAssembly backend (no threads)', async function () { ort.env.wasm.numThreads = 1; await testFunction(ort, { executionProviders: ['wasm'] }); diff --git a/js/web/test/e2e/browser-test-wasm-path-override-filename.js b/js/web/test/e2e/browser-test-wasm-path-override-filename.js index 5d99eb389b27a..e71a0840bedf6 100644 --- a/js/web/test/e2e/browser-test-wasm-path-override-filename.js +++ b/js/web/test/e2e/browser-test-wasm-path-override-filename.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +'use strict'; + it('Browser E2E testing - WebAssembly backend (path override filename)', async function () { // disable SIMD and multi-thread ort.env.wasm.numThreads = 1; diff --git a/js/web/test/e2e/browser-test-wasm-path-override-prefix.js b/js/web/test/e2e/browser-test-wasm-path-override-prefix.js index ff5d05f8c40d7..ebb6efe57bb75 100644 --- a/js/web/test/e2e/browser-test-wasm-path-override-prefix.js +++ b/js/web/test/e2e/browser-test-wasm-path-override-prefix.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +'use strict'; + it('Browser E2E testing - WebAssembly backend (path override prefix)', async function () { // disable SIMD and multi-thread diff --git a/js/web/test/e2e/browser-test-wasm.js b/js/web/test/e2e/browser-test-wasm.js index 9d91aed76dd8a..dec40f95b16c3 100644 --- a/js/web/test/e2e/browser-test-wasm.js +++ b/js/web/test/e2e/browser-test-wasm.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +'use strict'; + it('Browser E2E testing - WebAssembly backend', async function () { await testFunction(ort, { executionProviders: ['wasm'] }); }); diff --git a/js/web/test/e2e/browser-test-webgl.js b/js/web/test/e2e/browser-test-webgl.js index 4da09438dfa22..b5ac3e29a9617 100644 --- a/js/web/test/e2e/browser-test-webgl.js +++ b/js/web/test/e2e/browser-test-webgl.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +'use strict'; + it('Browser E2E testing - WebGL backend', async function () { await testFunction(ort, { executionProviders: ['webgl'] }); }); diff --git a/js/web/test/e2e/common.js b/js/web/test/e2e/common.js index e7b9b22ef1db6..4c0db6dc1a131 100644 --- a/js/web/test/e2e/common.js +++ b/js/web/test/e2e/common.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +'use strict'; + function assert(cond) { if (!cond) throw new Error(); } diff --git a/js/web/test/e2e/karma.conf.js b/js/web/test/e2e/karma.conf.js index 5c0e4740e6a5d..f45b7365f6b32 100644 --- a/js/web/test/e2e/karma.conf.js +++ b/js/web/test/e2e/karma.conf.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +'use strict'; + const args = require('minimist')(process.argv.slice(2)); const SELF_HOST = !!args['self-host']; const TEST_MAIN = args['test-main']; diff --git a/js/web/test/e2e/node-test-main-no-threads.js b/js/web/test/e2e/node-test-main-no-threads.js index 55204ff730845..15182a197de4d 100644 --- a/js/web/test/e2e/node-test-main-no-threads.js +++ b/js/web/test/e2e/node-test-main-no-threads.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +'use strict'; + const ort = require('onnxruntime-web'); const testFunction = require('./common'); diff --git a/js/web/test/e2e/node-test-main.js b/js/web/test/e2e/node-test-main.js index 29f4dfbdc0989..84d12a77b6cbf 100644 --- a/js/web/test/e2e/node-test-main.js +++ b/js/web/test/e2e/node-test-main.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +'use strict'; + const ort = require('onnxruntime-web'); const testFunction = require('./common'); diff --git a/js/web/test/e2e/node-test-wasm-path-override-filename.js b/js/web/test/e2e/node-test-wasm-path-override-filename.js index f9a4a7d2468c2..5ff6c358d9d9e 100644 --- a/js/web/test/e2e/node-test-wasm-path-override-filename.js +++ b/js/web/test/e2e/node-test-wasm-path-override-filename.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +'use strict'; + const path = require('path'); const ort = require('onnxruntime-web'); const testFunction = require('./common'); diff --git a/js/web/test/e2e/node-test-wasm-path-override-prefix.js b/js/web/test/e2e/node-test-wasm-path-override-prefix.js index 479c0859f379f..6416298bfe9aa 100644 --- a/js/web/test/e2e/node-test-wasm-path-override-prefix.js +++ b/js/web/test/e2e/node-test-wasm-path-override-prefix.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +'use strict'; + const path = require('path'); const ort = require('onnxruntime-web'); const testFunction = require('./common'); diff --git a/js/web/test/e2e/run.js b/js/web/test/e2e/run.js index a8f5727fadaad..095004d7a30bb 100644 --- a/js/web/test/e2e/run.js +++ b/js/web/test/e2e/run.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +'use strict'; + const path = require('path'); const fs = require('fs-extra'); const globby = require('globby'); diff --git a/js/web/test/e2e/simple-http-server.js b/js/web/test/e2e/simple-http-server.js index 7df59216c26ad..a6ae8c7e9b4d9 100644 --- a/js/web/test/e2e/simple-http-server.js +++ b/js/web/test/e2e/simple-http-server.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +'use strict'; + // this is a simple HTTP server that enables CORS. // following code is based on https://developer.mozilla.org/en-US/docs/Learn/Server-side/Node_server_without_framework diff --git a/js/web/test/unittests/index.ts b/js/web/test/unittests/index.ts index 92b86af64e283..6afdb720c53d3 100644 --- a/js/web/test/unittests/index.ts +++ b/js/web/test/unittests/index.ts @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +'use strict'; + if (typeof window !== 'undefined') { require('./backends/webgl/test-glsl-function-inliner'); require('./backends/webgl/test-conv-new'); diff --git a/js/web/webpack.config.js b/js/web/webpack.config.js index 452246029f4b0..0c938c11a2c4d 100644 --- a/js/web/webpack.config.js +++ b/js/web/webpack.config.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +'use strict'; + const path = require('path'); const webpack = require('webpack'); const NodePolyfillPlugin = require('node-polyfill-webpack-plugin'); diff --git a/onnxruntime/test/wasm/dump-test-result-in-nodejs.js b/onnxruntime/test/wasm/dump-test-result-in-nodejs.js index 5fe2a030ad15e..c012622efda29 100644 --- a/onnxruntime/test/wasm/dump-test-result-in-nodejs.js +++ b/onnxruntime/test/wasm/dump-test-result-in-nodejs.js @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +'use strict'; + // This file is used to be injected into "onnxruntime_test_all" as specified by flag "--pre-js" by emcc. // It dumps the test report file from emscripten's MEMFS to real file system diff --git a/samples/nodejs/01_basic-usage/index.js b/samples/nodejs/01_basic-usage/index.js index 73f959a768c68..886b7a9909a80 100644 --- a/samples/nodejs/01_basic-usage/index.js +++ b/samples/nodejs/01_basic-usage/index.js @@ -1,3 +1,4 @@ +'use strict'; const ort = require('onnxruntime'); // use an async context to call onnxruntime functions. diff --git a/samples/nodejs/02_create-tensor/index.js b/samples/nodejs/02_create-tensor/index.js index debe242696874..8c14d63bd3cde 100644 --- a/samples/nodejs/02_create-tensor/index.js +++ b/samples/nodejs/02_create-tensor/index.js @@ -1,3 +1,4 @@ +'use strict'; const Tensor = require('onnxruntime').Tensor; // diff --git a/samples/nodejs/04_create-inference-session/index.js b/samples/nodejs/04_create-inference-session/index.js index d75d33846cad8..0435f435a641c 100644 --- a/samples/nodejs/04_create-inference-session/index.js +++ b/samples/nodejs/04_create-inference-session/index.js @@ -1,3 +1,4 @@ +'use strict'; const fs = require('fs'); const util = require('util'); const InferenceSession = require('onnxruntime').InferenceSession;