Skip to content

Commit

Permalink
[JS] Migrate eslint to latest (#13825)
Browse files Browse the repository at this point in the history
* [JS] Migrate eslint to latest

* [JS] Update bazel targets

* [JS] Update copyright

* [JS] Update missing deps in bazel target

* [JS] Update code format

* [JS] Add eslint plugin for Node.js-specific linting rules
  • Loading branch information
harsha509 committed Apr 15, 2024
1 parent bfbed91 commit ec5757d
Show file tree
Hide file tree
Showing 103 changed files with 680 additions and 317 deletions.
1 change: 0 additions & 1 deletion javascript/node/selenium-webdriver/.eslintignore

This file was deleted.

44 changes: 0 additions & 44 deletions javascript/node/selenium-webdriver/.eslintrc.js

This file was deleted.

17 changes: 5 additions & 12 deletions javascript/node/selenium-webdriver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,15 @@ copy_to_bin(

eslint_bin.eslint_test(
name = "eslint-test",
args = [
"--ignore-pattern",
"node_modules",
"--ignore-pattern",
"generator",
"--ext",
"js",
"lib/http.js",
"**/*.js",
],
chdir = package_name(),
data = SRC_FILES + [
":eslint-config",
":node_modules/@eslint/js",
":node_modules/eslint-plugin-mocha",
":node_modules/eslint-plugin-n",
":node_modules/eslint-plugin-no-only-tests",
":node_modules/eslint-plugin-node",
":node_modules/eslint-plugin-prettier",
":node_modules/globals",
":node_modules/jszip",
":node_modules/mocha",
":node_modules/tmp",
Expand All @@ -216,7 +209,7 @@ eslint_bin.eslint_test(

copy_to_bin(
name = "eslint-config",
srcs = [".eslintrc.js"],
srcs = ["eslint.config.js"],
)

prettier_bin.prettier_test(
Expand Down
1 change: 0 additions & 1 deletion javascript/node/selenium-webdriver/bidi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.

// eslint-disable-next-line node/no-missing-require
const { EventEmitter } = require('node:events')
const WebSocket = require('ws')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const Type = {
* Described in https://w3c.github.io/webdriver-bidi/#command-storage-getCookies.
*/
class PartitionDescriptor {
/*eslint no-unused-private-class-members: "off"*/
#type

/**
Expand Down
8 changes: 4 additions & 4 deletions javascript/node/selenium-webdriver/common/seleniumManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
* Wrapper for getting information from the Selenium Manager binaries
*/

const { platform } = require('process')
const path = require('path')
const fs = require('fs')
const spawnSync = require('child_process').spawnSync
const { platform } = require('node:process')
const path = require('node:path')
const fs = require('node:fs')
const spawnSync = require('node:child_process').spawnSync
const { Capability } = require('../lib/capabilities')
const logging = require('../lib/logging')

Expand Down
107 changes: 107 additions & 0 deletions javascript/node/selenium-webdriver/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

const globals = require('globals')
const noOnlyTests = require('eslint-plugin-no-only-tests')
const js = require('@eslint/js')
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended')
const mochaPlugin = require('eslint-plugin-mocha')
const nodePlugin = require('eslint-plugin-n')

module.exports = [
js.configs.recommended,
eslintPluginPrettierRecommended,
mochaPlugin.configs.flat.recommended,
nodePlugin.configs['flat/recommended-script'],
{
languageOptions: {
globals: {
mocha: true,
es6: true,
...globals.node,
},
parserOptions: {
ecmaVersion: 2022,
},
},
files: ['**/*.js', 'lib/http.js'],
ignores: ['node_modules/*', 'generator/*', 'devtools/generator/'],
plugins: {
'no-only-tests': noOnlyTests,
},
rules: {
'no-const-assign': 'error',
'no-this-before-super': 'error',
'no-undef': 'error',
'no-unreachable': 'error',
'no-unused-vars': [
'error',
{
varsIgnorePattern: '^_',
args: 'all',
argsIgnorePattern: '^_',
},
],
'constructor-super': 'error',
'valid-typeof': 'error',
'no-only-tests/no-only-tests': 'error',
'n/no-deprecated-api': ['error'],
'n/no-missing-import': ['error'],
'n/no-missing-require': ['error'],
'n/no-mixed-requires': ['error'],
'n/no-new-require': ['error'],
'n/no-unpublished-import': ['error'],
'n/no-unpublished-require': [
'error',
{
allowModules: [
'globals',
'@eslint/js',
'eslint-plugin-mocha',
'eslint-plugin-prettier',
'eslint-plugin-n',
'eslint-plugin-no-only-tests',
],
tryExtensions: ['.js'],
},
],
'n/prefer-node-protocol': ['error'],
'mocha/no-skipped-tests': ['off'],
'mocha/no-mocha-arrows': ['off'],
'mocha/no-setup-in-describe': ['off'],
'mocha/no-top-level-hooks': ['off'],
'mocha/no-sibling-hooks': ['off'],
'mocha/no-exports': ['off'],
'mocha/no-empty-description': ['off'],
'mocha/max-top-level-suites': ['off'],
'mocha/consistent-spacing-between-blocks': ['off'],
'mocha/no-nested-tests': ['off'],
'mocha/no-pending-tests': ['off'],
'mocha/no-identical-title': ['off'],
'prettier/prettier': [
'error',
{
endOfLine: 'lf',
printWidth: 120,
semi: false,
singleQuote: true,
trailingComma: 'all',
},
],
},
},
]
4 changes: 2 additions & 2 deletions javascript/node/selenium-webdriver/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@

'use strict'

const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')
const Symbols = require('./lib/symbols')
const command = require('./lib/command')
const http = require('./http')
Expand Down
12 changes: 6 additions & 6 deletions javascript/node/selenium-webdriver/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

'use strict'

const http = require('http')
const https = require('https')
const url = require('url')
const http = require('node:http')
const https = require('node:https')
const url = require('node:url')

const httpLib = require('../lib/http')

Expand All @@ -45,7 +45,7 @@ let RequestOptions // eslint-disable-line
* @throws {Error} if the URL does not include a hostname.
*/
function getRequestOptions(aUrl) {
//eslint-disable-next-line node/no-deprecated-api
// eslint-disable-next-line n/no-deprecated-api
let options = url.parse(aUrl)
if (!options.hostname) {
throw new Error('Invalid URL: ' + aUrl)
Expand Down Expand Up @@ -140,7 +140,7 @@ class HttpClient {
} else {
path += httpRequest.path
}
//eslint-disable-next-line node/no-deprecated-api
// eslint-disable-next-line n/no-deprecated-api
let parsedPath = url.parse(path)

let options = {
Expand Down Expand Up @@ -218,7 +218,7 @@ function sendRequest(options, onOk, onError, opt_data, opt_proxy, opt_retries) {
if (response.statusCode == 302 || response.statusCode == 303) {
let location
try {
// eslint-disable-next-line node/no-deprecated-api
// eslint-disable-next-line n/no-deprecated-api
location = url.parse(response.headers['location'])
} catch (ex) {
onError(
Expand Down
2 changes: 1 addition & 1 deletion javascript/node/selenium-webdriver/io/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

'use strict'

const childProcess = require('child_process')
const childProcess = require('node:child_process')

/**
* Options for configuring an executed command.
Expand Down
5 changes: 3 additions & 2 deletions javascript/node/selenium-webdriver/io/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

'use strict'

const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')
const tmp = require('tmp')

/**
Expand Down Expand Up @@ -219,6 +219,7 @@ function findInPath(file, opt_checkCwd) {
try {
let stats = fs.statSync(tmp)
return stats.isFile() && !stats.isDirectory()
/*eslint no-unused-vars: "off"*/
} catch (ex) {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion javascript/node/selenium-webdriver/io/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'use strict'

const jszip = require('jszip')
const path = require('path')
const path = require('node:path')

const io = require('./index')
const { InvalidArgumentError } = require('../lib/error')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
// specific language governing permissions and limitations
// under the License.

const fs = require('fs')
const path = require('path')
const fs = require('node:fs')
const path = require('node:path')

if (process.argv.length < 3) {
process.stderr.write(`Usage: node ${path.basename(__filename)} <src file> <dst file>\n`)
// eslint-disable-next-line no-process-exit
// eslint-disable-next-line n/no-process-exit
process.exit(-1)
}

Expand Down
9 changes: 5 additions & 4 deletions javascript/node/selenium-webdriver/lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

'use strict'

const path = require('path')
const path = require('node:path')
const cmd = require('./command')
const error = require('./error')
const logging = require('./logging')
Expand Down Expand Up @@ -161,10 +161,10 @@ function resource(method, path) {
}

/** @typedef {{method: string, path: string}} */
var CommandSpec // eslint-disable-line
var CommandSpec

/** @typedef {function(!cmd.Command): !cmd.Command} */
var CommandTransformer // eslint-disable-line
var CommandTransformer

class InternalTypeError extends TypeError {}

Expand Down Expand Up @@ -337,7 +337,7 @@ class Client {
* @return {!Promise<Response>} A promise that will be fulfilled with the
* server's response.
*/
send(httpRequest) {} // eslint-disable-line
send(httpRequest) {}
}

/**
Expand Down Expand Up @@ -472,6 +472,7 @@ class Executor {
function tryParse(str) {
try {
return JSON.parse(str)
/*eslint no-unused-vars: "off"*/
} catch (ignored) {
// Do nothing.
}
Expand Down
1 change: 0 additions & 1 deletion javascript/node/selenium-webdriver/lib/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ class FileDetector {
* @package
*/
handleFile(_driver, path) {
// eslint-disable-line
return Promise.resolve(path)
}
}
Expand Down
2 changes: 1 addition & 1 deletion javascript/node/selenium-webdriver/lib/pinnedScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

const crypto = require('crypto')
const crypto = require('node:crypto')

class PinnedScript {
constructor(script) {
Expand Down
Loading

0 comments on commit ec5757d

Please sign in to comment.