Skip to content

Commit

Permalink
fullly lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jelly committed Nov 26, 2024
1 parent 0ce12ab commit 9860d1c
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions pkg/lib/cockpit/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck

import { url_root, calculate_application } from './_internal/location-utils';

Expand All @@ -31,9 +29,8 @@ export function get_window_location_hash() {
}

type Options = { [name: string]: string | Array<string> };
type Path = string | string[] | Location;

/* eslint prefer-rest-params: 0 */
/* eslint prefer-spread: 0 */
export class Location {
path: string[];
href: string;
Expand Down Expand Up @@ -81,17 +78,15 @@ export class Location {
return out;
}

#href_for_go_or_replace(/* ... */) {
let href;
if (arguments.length == 1 && arguments[0] instanceof Location) {
href = String(arguments[0]);
} else if (typeof arguments[0] == "string") {
const options = arguments[1] || { };
href = this.encode(this.decode(arguments[0], options), options);
#href_for_go_or_replace(path: Path, options?: Options) {
options = options || {};
if (typeof path === "string") {
return this.encode(this.decode(path, options), options);
} else if (path instanceof Location) {
return path.href;
} else {
href = this.encode.apply(this, arguments);
return this.encode(path, options);
}
return href;
}

#decode_path(input: string) {
Expand Down Expand Up @@ -155,10 +150,10 @@ export class Location {

decode(href: string, options: Options) {
if (href[0] == '#')
href = href.substr(1);
href = href.substring(1);

const pos = href.indexOf('?');
const first = (pos === -1) ? href : href.substr(0, pos);
const first = (pos === -1) ? href : href.substring(0, pos);
const path = this.#decode_path(first);
if (pos !== -1 && options) {
href.substring(pos + 1).split("&")

Check failure

Code scanning / CodeQL

Remote property injection High

A property name to write to depends on a
user-provided value
.
Expand All @@ -168,7 +163,7 @@ export class Location {
const value = decodeURIComponent(parts[1]);
if (options[name]) {
let last = options[name];
if (!Array.isArray(value))
if (!Array.isArray(last))
last = options[name] = [last];
last.push(value);
} else {
Expand All @@ -180,19 +175,17 @@ export class Location {
return path;
}

// replace with string[] | string, options
replace(/* ... */) {
replace(path: Path, options?: Options) {
if (this.#hash_changed)
return;
const href = this.#href_for_go_or_replace.apply(this, arguments);
const href = this.#href_for_go_or_replace(path, options);
window.location.replace(window.location.pathname + '#' + href);
}

// replace with string[] | string, options?
go(/* ... */) {
go(path: Path, options?: Options) {
if (this.#hash_changed)
return;
const href = this.#href_for_go_or_replace.apply(this, arguments);
const href = this.#href_for_go_or_replace(path, options);
window.location.hash = '#' + href;
}

Expand Down

0 comments on commit 9860d1c

Please sign in to comment.