From 674ce17834aa93b8b2aa6fb9ada00a51c9f5fe55 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Sat, 29 May 2021 14:48:56 -0400 Subject: [PATCH] fix nearly all lint errors now --- css/augmentations.scss | 1 - css/bladeburner.scss | 2 +- css/casino.scss | 2 +- css/dev-menu.css | 8 ++---- css/grid.min.css | 1 + css/redpill.scss | 2 +- css/styles.scss | 12 ++++---- css/treant.css | 2 +- src/Augmentation/ui/Root.tsx | 5 ++-- src/Bladeburner/Action.ts | 2 ++ src/CodingContracts.ts | 5 +--- src/ExportBonus.tsx | 4 +++ src/NetscriptFunctions.js | 5 ++-- src/NetscriptWorker.js | 8 +++--- src/PersonObjects/Sleeve/Sleeve.ts | 4 +-- .../Sleeve/SleeveTaskTypesEnum.ts | 2 +- src/RedPill.js | 1 - src/SaveObject.jsx | 8 +++--- src/Script/RamCalculations.js | 1 + src/ScriptEditor/Ace.js | 28 +++++++++---------- src/ScriptEditor/CodeMirror.js | 6 +++- src/ScriptEditor/ScriptEditor.js | 2 +- src/Terminal.jsx | 1 - src/ui/React/CodingContractPopup.tsx | 17 +++++++---- src/ui/React/PopupButton.tsx | 10 +++---- src/ui/setSettingsLabels.js | 1 - stylelint.config.js | 2 +- webpack.config-test.js | 1 + webpack.config.js | 1 + 29 files changed, 75 insertions(+), 69 deletions(-) diff --git a/css/augmentations.scss b/css/augmentations.scss index 36b39a4e2..d1043459d 100644 --- a/css/augmentations.scss +++ b/css/augmentations.scss @@ -27,5 +27,4 @@ button { padding: 4px; } - } diff --git a/css/bladeburner.scss b/css/bladeburner.scss index cc8ce3189..ef46b422f 100644 --- a/css/bladeburner.scss +++ b/css/bladeburner.scss @@ -80,7 +80,7 @@ transform: rotate(-45deg); } } - input[type=checkbox] { + input[type="checkbox"] { margin: 3px; visibility: hidden; &:checked + label:after { diff --git a/css/casino.scss b/css/casino.scss index c7cd6280a..aceb02f17 100644 --- a/css/casino.scss +++ b/css/casino.scss @@ -11,7 +11,7 @@ } .casino-card .value { - font-size:15pt; + font-size: 15pt; font-family: sans-serif; } diff --git a/css/dev-menu.css b/css/dev-menu.css index 10e7c058c..c4cf10a69 100644 --- a/css/dev-menu.css +++ b/css/dev-menu.css @@ -3,15 +3,11 @@ } .remove-exp-button { - margin-left:0; + margin-left: 0; } .exp-input { - margin-right: 0; - margin-left:0; - - margin-top: 5px; - margin-bottom: 5px; + margin: 5px 0 5px 0; padding: 2px 5px; } diff --git a/css/grid.min.css b/css/grid.min.css index c32112cbb..dac714e89 100644 --- a/css/grid.min.css +++ b/css/grid.min.css @@ -1,3 +1,4 @@ +/* stylelint-disable */ /*! * Bootstrap Grid v4.1.2 (https://getbootstrap.com/) * Copyright 2011-2018 The Bootstrap Authors diff --git a/css/redpill.scss b/css/redpill.scss index 7bcedc6a6..0f11b27f7 100644 --- a/css/redpill.scss +++ b/css/redpill.scss @@ -17,7 +17,7 @@ } &.level-2 { - color: #48d1cc; + color: #48d1cc; } &.level-3 { diff --git a/css/styles.scss b/css/styles.scss index a6c98b897..ecc67e439 100644 --- a/css/styles.scss +++ b/css/styles.scss @@ -234,9 +234,9 @@ a:visited { #status-text-container { background-color: transparent; - position:absolute; - top:0; - left:50%; + position: absolute; + top: 0; + left: 50%; } #status-text { @@ -371,14 +371,15 @@ a:visited { .noscrollbar { -ms-overflow-style: none; /* IE and Edge */ - scrollbar-width: none; /* Firefox */ + /* stylelint-disable-next-line property-no-unknown */ + scrollbar-width: none; /* Firefox https://developer.mozilla.org/en-US/docs/Web/CSS/scrollbar-width */ } .noscrollbar::-webkit-scrollbar { display: none; } -input[type=checkbox] { +input[type="checkbox"] { filter: invert(1) sepia(1) hue-rotate(41deg) brightness(100%) saturate(10); } @@ -398,7 +399,6 @@ input[type=checkbox] { margin: 3px; } - .optionRange::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; diff --git a/css/treant.css b/css/treant.css index 38917ce34..482d8d746 100644 --- a/css/treant.css +++ b/css/treant.css @@ -16,7 +16,7 @@ text-align: center; border: 2px solid #e8e8e3; border-radius: 2px; - box-shadow: 1px 1px 1px rgba(0,0,0,0.5); + box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5); font-size: 12px; } diff --git a/src/Augmentation/ui/Root.tsx b/src/Augmentation/ui/Root.tsx index f5315ed24..228ed5756 100644 --- a/src/Augmentation/ui/Root.tsx +++ b/src/Augmentation/ui/Root.tsx @@ -10,8 +10,7 @@ import { PurchasedAugmentations } from "./PurchasedAugmentations"; import { Player } from "../../Player"; import { StdButton } from "../../ui/React/StdButton"; -import { LastExportBonus, canGetBonus } from "../../ExportBonus"; -import { convertTimeMsToTimeElapsedString } from "../../../utils/StringHelperFunctions"; +import { canGetBonus } from "../../ExportBonus"; type IProps = { exportGameFn: () => void; @@ -31,7 +30,7 @@ export class AugmentationsRoot extends React.Component { this.export = this.export.bind(this); } - export() { + export(): void { this.props.exportGameFn(); this.setState({ rerender: !this.state.rerender, diff --git a/src/Bladeburner/Action.ts b/src/Bladeburner/Action.ts index e4e42d749..4ed69d0c9 100644 --- a/src/Bladeburner/Action.ts +++ b/src/Bladeburner/Action.ts @@ -164,10 +164,12 @@ export class Action implements IAction { } // For actions that have teams. To be implemented by subtypes. + // eslint-disable-next-line @typescript-eslint/no-unused-vars getTeamSuccessBonus(inst: IBladeburner): number { return 1; } + // eslint-disable-next-line @typescript-eslint/no-unused-vars getActionTypeSkillSuccessBonus(inst: IBladeburner): number { return 1; } diff --git a/src/CodingContracts.ts b/src/CodingContracts.ts index 34c6673a9..31dc995c1 100644 --- a/src/CodingContracts.ts +++ b/src/CodingContracts.ts @@ -12,10 +12,7 @@ import { Generic_toJSON, Reviver, } from "../utils/JSONReviver"; -import { KEY } from "../utils/helpers/keyCodes"; -import { createElement } from "../utils/uiHelpers/createElement"; import { createPopup, removePopup } from "./ui/React/createPopup"; -import { removeElementById } from "../utils/uiHelpers/removeElementById"; import { CodingContractPopup } from "./ui/React/CodingContractPopup"; @@ -174,7 +171,7 @@ export class CodingContract { */ async prompt(): Promise { const popupId = `coding-contract-prompt-popup-${this.fn}`; - return new Promise((resolve, reject) => { + return new Promise((resolve) => { const popup = new CodingContractPopup({ c: this, popupId: popupId, diff --git a/src/ExportBonus.tsx b/src/ExportBonus.tsx index 6437d292b..3a4861308 100644 --- a/src/ExportBonus.tsx +++ b/src/ExportBonus.tsx @@ -16,4 +16,8 @@ export function onExport(p: IPlayer): void { Factions[facName].favor++; } LastExportBonus = (new Date()).getTime(); +} + +export function setLastExportBonus(unixTime: number): void { + LastExportBonus = unixTime; } \ No newline at end of file diff --git a/src/NetscriptFunctions.js b/src/NetscriptFunctions.js index 106f76740..429af00f8 100644 --- a/src/NetscriptFunctions.js +++ b/src/NetscriptFunctions.js @@ -1,5 +1,4 @@ -const sprintf = require("sprintf-js").sprintf; -const vsprintf = require("sprintf-js").vsprintf; +import { vsprintf, sprintf } from 'sprintf-js'; import * as libarg from 'arg'; import { getRamCost } from "./Netscript/RamCostGenerator"; @@ -4397,7 +4396,7 @@ function NetscriptFunctions(workerScript) { hacknetServers: { hashGainRate: function(level, ramUsed, maxRam, cores, mult=1) { checkFormulasAccess("hacknetServers.hashGainRate", 9); - return HScalculateHashGainRate(level, ramUsed, maxRam, cores, mult=1); + return HScalculateHashGainRate(level, ramUsed, maxRam, cores, mult); }, levelUpgradeCost: function(startingLevel, extraLevels=1, costMult=1) { checkFormulasAccess("hacknetServers.levelUpgradeCost", 9); diff --git a/src/NetscriptWorker.js b/src/NetscriptWorker.js index cd38ea37e..226c9c57e 100644 --- a/src/NetscriptWorker.js +++ b/src/NetscriptWorker.js @@ -34,7 +34,7 @@ import { roundToTwo } from "../utils/helpers/roundToTwo"; import { isString } from "../utils/StringHelperFunctions"; import { parse } from "acorn"; -const walk = require("acorn-walk"); +import { simple as walksimple } from "acorn-walk"; // Netscript Ports are instantiated here export const NetscriptPorts = []; @@ -304,7 +304,7 @@ function processNetscript1Imports(code, workerScript) { let hasImports = false; // Walk over the tree and process ImportDeclaration nodes - walk.simple(ast, { + walksimple(ast, { ImportDeclaration: (node) => { hasImports = true; let scriptName = node.source.value; @@ -322,7 +322,7 @@ function processNetscript1Imports(code, workerScript) { let namespace = node.specifiers[0].local.name; let fnNames = []; //Names only let fnDeclarations = []; //FunctionDeclaration Node objects - walk.simple(scriptAst, { + walksimple(scriptAst, { FunctionDeclaration: (node) => { fnNames.push(node.id.name); fnDeclarations.push(node); @@ -361,7 +361,7 @@ function processNetscript1Imports(code, workerScript) { //Walk through script and get FunctionDeclaration code for all specified fns let fnDeclarations = []; - walk.simple(scriptAst, { + walksimple(scriptAst, { FunctionDeclaration: (node) => { if (fnsToImport.includes(node.id.name)) { fnDeclarations.push(node); diff --git a/src/PersonObjects/Sleeve/Sleeve.ts b/src/PersonObjects/Sleeve/Sleeve.ts index dc05f57b4..bb5f17932 100644 --- a/src/PersonObjects/Sleeve/Sleeve.ts +++ b/src/PersonObjects/Sleeve/Sleeve.ts @@ -529,7 +529,7 @@ export class Sleeve extends Person { case SleeveTaskType.Recovery: this.shock = Math.min(100, this.shock + (0.0002 * cyclesUsed)); break; - case SleeveTaskType.Sync: + case SleeveTaskType.Synchro: this.sync = Math.min(100, this.sync + (p.getIntelligenceBonus(0.5) * 0.0002 * cyclesUsed)); break; default: @@ -586,7 +586,7 @@ export class Sleeve extends Person { this.resetTaskStatus(); } - this.currentTask = SleeveTaskType.Sync; + this.currentTask = SleeveTaskType.Synchro; return true; } diff --git a/src/PersonObjects/Sleeve/SleeveTaskTypesEnum.ts b/src/PersonObjects/Sleeve/SleeveTaskTypesEnum.ts index 78a3bd49f..ad83b4368 100644 --- a/src/PersonObjects/Sleeve/SleeveTaskTypesEnum.ts +++ b/src/PersonObjects/Sleeve/SleeveTaskTypesEnum.ts @@ -10,5 +10,5 @@ export enum SleeveTaskType { Class, Gym, Recovery, - Sync, + Synchro, } diff --git a/src/RedPill.js b/src/RedPill.js index ec091c21f..987a49371 100644 --- a/src/RedPill.js +++ b/src/RedPill.js @@ -8,7 +8,6 @@ import { prestigeSourceFile } from "./Prestige"; import { PlayerOwnedSourceFile } from "./SourceFile/PlayerOwnedSourceFile"; import { SourceFileFlags } from "./SourceFile/SourceFileFlags"; import { SourceFiles } from "./SourceFile/SourceFiles"; -import { Terminal } from "./Terminal"; import { setTimeoutRef } from "./utils/SetTimeoutRef"; import { dialogBoxCreate } from "../utils/DialogBox"; diff --git a/src/SaveObject.jsx b/src/SaveObject.jsx index 4e190855d..fc17fa8a4 100755 --- a/src/SaveObject.jsx +++ b/src/SaveObject.jsx @@ -248,9 +248,9 @@ function loadGame(saveString) { } if (saveObj.hasOwnProperty("LastExportBonus")) { try { - ExportBonus.LastExportBonus = JSON.parse(saveObj.LastExportBonus); + ExportBonus.setLastExportBonus(JSON.parse(saveObj.LastExportBonus)); } catch(err) { - ExportBonus.LastExportBonus = (new Date()).getTime(); + ExportBonus.setLastExportBonus((new Date()).getTime()); console.error("ERROR: Failed to parse .fconf Settings "+ err); } } @@ -334,9 +334,9 @@ function loadImportedGame(saveObj, saveString) { } if (saveObj.hasOwnProperty("LastExportBonus")) { try { - ExportBonus.LastExportBonus = JSON.parse(saveObj.LastExportBonus); + ExportBonus.setLastExportBonus(JSON.parse(saveObj.LastExportBonus)); } catch(err) { - ExportBonus.LastExportBonus = (new Date()).getTime(); + ExportBonus.setLastExportBonus((new Date()).getTime()); console.error("ERROR: Failed to parse .fconf Settings "+ err); } } diff --git a/src/Script/RamCalculations.js b/src/Script/RamCalculations.js index 7aa6920fa..36dfc856c 100644 --- a/src/Script/RamCalculations.js +++ b/src/Script/RamCalculations.js @@ -78,6 +78,7 @@ async function parseOnlyRamCalculate(otherScripts, code, workerScript) { let code; if (nextModule.startsWith("https://") || nextModule.startsWith("http://")) { try { + // eslint-disable-next-line no-await-in-loop const module = await eval('import(nextModule)'); code = ""; for (const prop in module) { diff --git a/src/ScriptEditor/Ace.js b/src/ScriptEditor/Ace.js index 65926758f..78f25f0ec 100644 --- a/src/ScriptEditor/Ace.js +++ b/src/ScriptEditor/Ace.js @@ -1,20 +1,20 @@ import { ScriptEditor } from "./ScriptEditor"; -const ace = require('brace'); +import ace from 'brace'; -require('brace/mode/javascript'); -require('./AceNetscriptMode'); -require('brace/theme/chaos'); -require('brace/theme/chrome'); -require('brace/theme/monokai'); -require('brace/theme/solarized_dark'); -require('brace/theme/solarized_light'); -require('brace/theme/terminal'); -require('brace/theme/twilight'); -require('brace/theme/xcode'); -require("brace/keybinding/vim"); -require("brace/keybinding/emacs"); -require("brace/ext/language_tools"); +import 'brace/mode/javascript'; +import './AceNetscriptMode'; +import 'brace/theme/chaos'; +import 'brace/theme/chrome'; +import 'brace/theme/monokai'; +import 'brace/theme/solarized_dark'; +import 'brace/theme/solarized_light'; +import 'brace/theme/terminal'; +import 'brace/theme/twilight'; +import 'brace/theme/xcode'; +import "brace/keybinding/vim"; +import "brace/keybinding/emacs"; +import "brace/ext/language_tools"; import { NetscriptFunctions } from "../NetscriptFunctions"; import { Settings } from "../Settings/Settings"; diff --git a/src/ScriptEditor/CodeMirror.js b/src/ScriptEditor/CodeMirror.js index cc2d3c4e3..4093fdf69 100644 --- a/src/ScriptEditor/CodeMirror.js +++ b/src/ScriptEditor/CodeMirror.js @@ -87,7 +87,7 @@ import 'codemirror/addon/lint/lint.css'; import 'codemirror/addon/search/match-highlighter.js'; import 'codemirror/addon/selection/active-line.js'; -window.JSHINT = require('jshint').JSHINT; +import { JSHINT } from 'jshint'; import './CodeMirrorNetscriptLint.js'; import { NetscriptFunctions } from "../NetscriptFunctions"; @@ -100,6 +100,10 @@ import { createElement } from "../../utils/uiHelpers/createElement"; import { createOptionElement } from "../../utils/uiHelpers/createOptionElement"; import { removeChildrenFromElement } from "../../utils/uiHelpers/removeChildrenFromElement"; +(function() { + window.JSHINT = JSHINT; +})(); + // Max number of invisibles to be shown in a group if the "Show Invisibles" option // is marked const MaxInvisibles = 20; diff --git a/src/ScriptEditor/ScriptEditor.js b/src/ScriptEditor/ScriptEditor.js index d00b81616..dc2b301a7 100644 --- a/src/ScriptEditor/ScriptEditor.js +++ b/src/ScriptEditor/ScriptEditor.js @@ -1,7 +1,7 @@ import { CursorPositions } from './CursorPositions'; // Base Script Editor class for the Ace/CodeMirror/etc. wrappers -const beautify = require('js-beautify').js_beautify; +import { js_beautify as beautify } from 'js-beautify'; export class ScriptEditor { constructor() { diff --git a/src/Terminal.jsx b/src/Terminal.jsx index 2ba8f9d57..0af22e1de 100644 --- a/src/Terminal.jsx +++ b/src/Terminal.jsx @@ -588,7 +588,6 @@ let Terminal = { post(currServ.hostname + ": "); const org = currServ.organizationName post("Organization name: " + (!isHacknet ? org : "Player")); - const admin = currServ.hasAdminRights; let hasAdminRights = !isHacknet && currServ.hasAdminRights || isHacknet; post("Root Access: " + (hasAdminRights ? "YES" : "NO")); const hackingSkill = currServ.requiredHackingSkill diff --git a/src/ui/React/CodingContractPopup.tsx b/src/ui/React/CodingContractPopup.tsx index ca36585f0..0337cb16e 100644 --- a/src/ui/React/CodingContractPopup.tsx +++ b/src/ui/React/CodingContractPopup.tsx @@ -24,16 +24,21 @@ export class CodingContractPopup extends React.Component{ this.onInputKeydown = this.onInputKeydown.bind(this); } - setAnswer(event: any) { + setAnswer(event: React.ChangeEvent): void { this.setState({ answer: event.target.value }); } - onInputKeydown(e:any){ - if (e.keyCode === KEY.ENTER && e.target.value !== "") { - e.preventDefault(); + onInputKeydown(event: React.KeyboardEvent): void { + // React just won't cooperate on this one. + // "React.KeyboardEvent" seems like the right type but + // whatever ... + const value = (event.target as any).value; + + if (event.keyCode === KEY.ENTER && value !== "") { + event.preventDefault(); this.props.onAttempt(this.state.answer); - } else if (e.keyCode === KEY.ESC) { - e.preventDefault(); + } else if (event.keyCode === KEY.ESC) { + event.preventDefault(); this.props.onClose(); } } diff --git a/src/ui/React/PopupButton.tsx b/src/ui/React/PopupButton.tsx index 6a6bd4868..c4c9f1d70 100644 --- a/src/ui/React/PopupButton.tsx +++ b/src/ui/React/PopupButton.tsx @@ -14,7 +14,7 @@ import { removeElement } from "../../../utils/uiHelpers/removeElement"; export interface IPopupButtonProps { class?: string; popup: HTMLElement | string; - style?: object; + style?: any; text: string; onClose?: () => void; } @@ -26,15 +26,15 @@ export class PopupButton extends React.Component { this.keyListener = this.keyListener.bind(this); } - componentDidMount() { + componentDidMount(): void { document.addEventListener("keydown", this.keyListener); } - componentWillUnmount() { + componentWillUnmount(): void { document.removeEventListener("keydown", this.keyListener); } - handleClick() { + handleClick(): void { if(this.props.onClose) this.props.onClose(); //We might be able to remove this? @@ -52,7 +52,7 @@ export class PopupButton extends React.Component { } } - keyListener(e: KeyboardEvent) { + keyListener(e: KeyboardEvent): void { //This doesn't really make sense, a button doesnt have to listen to escape IMO //Too affraid to remove it since im not sure what it will break.. But yuck.. if (e.keyCode === KEY.ESC) { diff --git a/src/ui/setSettingsLabels.js b/src/ui/setSettingsLabels.js index bdeb8b7e5..bf8ba0426 100644 --- a/src/ui/setSettingsLabels.js +++ b/src/ui/setSettingsLabels.js @@ -1,6 +1,5 @@ import {Engine} from "../engine"; import {Settings} from "../Settings/Settings"; -import {Player} from "../Player"; import {numeralWrapper} from "./numeralFormat"; diff --git a/stylelint.config.js b/stylelint.config.js index 6a3a7e05e..76a82fd04 100644 --- a/stylelint.config.js +++ b/stylelint.config.js @@ -44,7 +44,7 @@ module.exports = { // "block-opening-brace-space-before": "always", "color-hex-case": "lower", "color-hex-length": "short", - "color-named": "never", +// "color-named": "never", //"color-no-hex": true, "color-no-invalid-hex": true, // "comment-empty-line-before": "always", diff --git a/webpack.config-test.js b/webpack.config-test.js index 72cf7b365..8d5ca3a27 100644 --- a/webpack.config-test.js +++ b/webpack.config-test.js @@ -1,6 +1,7 @@ /** * Webpack configuration for building unit tests */ + /* eslint-disable @typescript-eslint/no-var-requires */ var path = require('path'); var webpack = require('webpack'); diff --git a/webpack.config.js b/webpack.config.js index 2ef501949..22d542297 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ var path = require('path'); var webpack = require('webpack'); var MiniCssExtractPlugin = require('mini-css-extract-plugin');