diff --git a/.changeset/few-jokes-travel.md b/.changeset/few-jokes-travel.md new file mode 100644 index 0000000000..b4a57f6823 --- /dev/null +++ b/.changeset/few-jokes-travel.md @@ -0,0 +1,8 @@ +--- +"@khanacademy/kas": patch +"@khanacademy/perseus": patch +"@khanacademy/perseus-editor": patch +"@khanacademy/simple-markdown": patch +--- + +Fix some file-wide error suppressions diff --git a/config/test/test-setup.ts b/config/test/test-setup.ts index f907ec797a..cd4bf6f5cf 100644 --- a/config/test/test-setup.ts +++ b/config/test/test-setup.ts @@ -35,7 +35,6 @@ if (typeof window !== "undefined") { // Override the window.location implementation to mock out assign() // We need to access window.location.assign to verify that we're // redirecting to the right place. - /* eslint-disable no-restricted-syntax */ const oldLocation = window.location; // @ts-expect-error - TS2790 - The operand of a 'delete' operator must be optional. delete window.location; diff --git a/packages/kas/src/nodes.ts b/packages/kas/src/nodes.ts index 6aca9a49e2..9d33c1fe05 100644 --- a/packages/kas/src/nodes.ts +++ b/packages/kas/src/nodes.ts @@ -1,7 +1,7 @@ /* eslint-disable prettier/prettier */ /* eslint-disable import/order */ /* TODO(charlie): fix these lint errors (http://eslint.org/docs/rules): */ -/* eslint-disable indent, no-undef, no-var, one-var, no-dupe-keys, no-new-func, no-redeclare, @typescript-eslint/no-unused-vars, comma-dangle, max-len, prefer-spread, space-infix-ops, space-unary-ops */ +/* eslint-disable indent, no-undef, no-var, no-dupe-keys, no-new-func, no-redeclare, comma-dangle, max-len, prefer-spread, space-infix-ops, space-unary-ops */ import _ from "underscore"; import {unitParser} from "./__genfiles__/unitparser"; @@ -1414,7 +1414,6 @@ export class Mul extends Seq { rational = rational.addHint("fraction"); } - var result; if (num.n < 0 && right.n < 0) { rational.d = -rational.d; return left.replace(num, [NumNeg, rational]); diff --git a/packages/perseus-editor/src/__stories__/item-editor.stories.tsx b/packages/perseus-editor/src/__stories__/item-editor.stories.tsx index 26862e4c5d..cef53e11bf 100644 --- a/packages/perseus-editor/src/__stories__/item-editor.stories.tsx +++ b/packages/perseus-editor/src/__stories__/item-editor.stories.tsx @@ -10,7 +10,6 @@ import "../styles/perseus-editor.less"; type Props = React.ComponentProps; const Wrapper = (props: Props) => { - // eslint-disable-next-line @typescript-eslint/no-unused-vars const {onChange, ...rest} = props; const [extras, setExtras] = React.useState>(rest); @@ -19,7 +18,7 @@ const Wrapper = (props: Props) => { { - props.onChange?.(e); // to register action in storybook + onChange?.(e); // to register action in storybook setExtras((prevExtras) => ({...prevExtras, ...e})); }} /> diff --git a/packages/perseus-editor/src/multirenderer-editor.tsx b/packages/perseus-editor/src/multirenderer-editor.tsx index 9a9264b1f8..2d0445c7fd 100644 --- a/packages/perseus-editor/src/multirenderer-editor.tsx +++ b/packages/perseus-editor/src/multirenderer-editor.tsx @@ -31,8 +31,7 @@ import type { // Multi-item item types Item, - // ItemTree is used below, the linter is confused. - ItemTree, // eslint-disable-line @typescript-eslint/no-unused-vars + ItemTree, ItemObjectNode, ItemArrayNode, ContentNode, diff --git a/packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-function-settings.test.tsx b/packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-function-settings.test.tsx index 5caaf10b6e..3d9df676d1 100644 --- a/packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-function-settings.test.tsx +++ b/packages/perseus-editor/src/widgets/interactive-graph-editor/locked-figures/locked-function-settings.test.tsx @@ -5,9 +5,6 @@ import * as React from "react"; import {flags} from "../../../__stories__/flags-for-api-options"; -// Disabling the following linting error because the import is needed for mocking purposes. -// eslint-disable-next-line @typescript-eslint/no-unused-vars -import examples from "./locked-function-examples"; import LockedFunctionSettings from "./locked-function-settings"; import { getDefaultFigureForType, diff --git a/packages/perseus-editor/src/widgets/orderer-editor.tsx b/packages/perseus-editor/src/widgets/orderer-editor.tsx index c4a9b20b97..d841ce0799 100644 --- a/packages/perseus-editor/src/widgets/orderer-editor.tsx +++ b/packages/perseus-editor/src/widgets/orderer-editor.tsx @@ -1,5 +1,5 @@ /* eslint-disable @khanacademy/ts-no-error-suppressions */ -/* eslint-disable one-var, react/forbid-prop-types */ +/* eslint-disable react/forbid-prop-types */ import {components} from "@khanacademy/perseus"; import PropTypes from "prop-types"; import * as React from "react"; @@ -7,10 +7,10 @@ import _ from "underscore"; const {InfoTip, TextListEditor} = components; -const NORMAL = "normal", - AUTO = "auto", - HORIZONTAL = "horizontal", - VERTICAL = "vertical"; +const NORMAL = "normal"; +const AUTO = "auto"; +const HORIZONTAL = "horizontal"; +const VERTICAL = "vertical"; type Props = any; diff --git a/packages/perseus/src/hints-renderer.tsx b/packages/perseus/src/hints-renderer.tsx index 8cf5145039..ee57f01b99 100644 --- a/packages/perseus/src/hints-renderer.tsx +++ b/packages/perseus/src/hints-renderer.tsx @@ -1,4 +1,3 @@ -/* eslint-disable @khanacademy/ts-no-error-suppressions */ import * as PerseusLinter from "@khanacademy/perseus-linter"; import {StyleSheet, css} from "aphrodite"; import classnames from "classnames"; diff --git a/packages/perseus/src/interactive2/wrapped-drawing.ts b/packages/perseus/src/interactive2/wrapped-drawing.ts index a6e4599a5e..6b9c47b136 100644 --- a/packages/perseus/src/interactive2/wrapped-drawing.ts +++ b/packages/perseus/src/interactive2/wrapped-drawing.ts @@ -1,4 +1,3 @@ -/* eslint-disable @babel/no-invalid-this */ /** * Default methods for a wrapped movable. */ diff --git a/packages/perseus/src/perseus-markdown.tsx b/packages/perseus/src/perseus-markdown.tsx index 47be9731b1..472cce4403 100644 --- a/packages/perseus/src/perseus-markdown.tsx +++ b/packages/perseus/src/perseus-markdown.tsx @@ -1,4 +1,3 @@ -/* eslint-disable no-useless-escape, no-prototype-builtins */ import {pureMarkdownRules} from "@khanacademy/pure-markdown"; import SimpleMarkdown from "@khanacademy/simple-markdown"; import * as React from "react"; @@ -201,7 +200,7 @@ const rules = { // link was not put together properly, let's make sure it's there so we // don't break the entire page. const isKAUrl = href - ? href.match(/https?:\/\/[^\/]*khanacademy.org|^\//) + ? href.match(/https?:\/\/[^/]*khanacademy.org|^\//) : false; if (!isKAUrl) { // Prevents "reverse tabnabbing" phishing attacks diff --git a/packages/perseus/src/perseus-types.ts b/packages/perseus/src/perseus-types.ts index 95dd9993d5..f0d251c768 100644 --- a/packages/perseus/src/perseus-types.ts +++ b/packages/perseus/src/perseus-types.ts @@ -1171,9 +1171,9 @@ export type PerseusOrdererWidgetOptions = { // Cards that are not part of the answer otherOptions: ReadonlyArray; // "normal" for text options. "auto" for image options. - height: string; + height: "normal" | "auto"; // Use the "horizontal" layout for short text and small images. The "vertical" layout is best for longer text (e.g. proofs). - layout: string; + layout: "horizontal" | "vertical"; }; export type PerseusPassageWidgetOptions = { diff --git a/packages/perseus/src/util.ts b/packages/perseus/src/util.ts index 0efb5a3da8..d50781e975 100644 --- a/packages/perseus/src/util.ts +++ b/packages/perseus/src/util.ts @@ -1,4 +1,3 @@ -/* eslint-disable @babel/no-invalid-this, getter-return, one-var */ import {Errors, PerseusError} from "@khanacademy/perseus-core"; import _ from "underscore"; @@ -150,8 +149,8 @@ function shuffle( do { // Fischer-Yates shuffle for (let top = shuffled.length; top > 0; top--) { - const newEnd = Math.floor(random() * top), - temp = shuffled[newEnd]; + const newEnd = Math.floor(random() * top); + const temp = shuffled[newEnd]; // @ts-expect-error - TS2542 - Index signature in type 'readonly T[]' only permits reading. shuffled[newEnd] = shuffled[top - 1]; diff --git a/packages/perseus/src/util/graphie.ts b/packages/perseus/src/util/graphie.ts index 308efaf7f3..7909feeb95 100644 --- a/packages/perseus/src/util/graphie.ts +++ b/packages/perseus/src/util/graphie.ts @@ -1,4 +1,3 @@ -/* eslint-disable @babel/no-invalid-this */ import { point as kpoint, vector as kvector, diff --git a/packages/perseus/src/util/parse-perseus-json/perseus-parsers/orderer-widget.ts b/packages/perseus/src/util/parse-perseus-json/perseus-parsers/orderer-widget.ts index 4c8f72e52c..b0c72ab602 100644 --- a/packages/perseus/src/util/parse-perseus-json/perseus-parsers/orderer-widget.ts +++ b/packages/perseus/src/util/parse-perseus-json/perseus-parsers/orderer-widget.ts @@ -1,4 +1,4 @@ -import {array, constant, object, string} from "../general-purpose-parsers"; +import {array, constant, enumeration, object} from "../general-purpose-parsers"; import {parsePerseusRenderer} from "./perseus-renderer"; import {parseWidget} from "./widget"; @@ -19,7 +19,7 @@ export const parseOrdererWidget: Parser = parseWidget( options: array(parseRenderer), correctOptions: array(parseRenderer), otherOptions: array(parseRenderer), - height: string, - layout: string, + height: enumeration("normal", "auto"), + layout: enumeration("horizontal", "vertical"), }), ); diff --git a/packages/perseus/src/util/parse-perseus-json/perseus-parsers/widgets-map.test.ts b/packages/perseus/src/util/parse-perseus-json/perseus-parsers/widgets-map.test.ts index 9d6a672364..3b21b880e4 100644 --- a/packages/perseus/src/util/parse-perseus-json/perseus-parsers/widgets-map.test.ts +++ b/packages/perseus/src/util/parse-perseus-json/perseus-parsers/widgets-map.test.ts @@ -512,8 +512,8 @@ describe("parseWidgetsMap", () => { options: [], correctOptions: [], otherOptions: [], - height: "", - layout: "", + height: "normal", + layout: "horizontal", }, }, }; diff --git a/packages/perseus/src/widgets/grapher/util.tsx b/packages/perseus/src/widgets/grapher/util.tsx index fa3a684e58..ed7c6af887 100644 --- a/packages/perseus/src/widgets/grapher/util.tsx +++ b/packages/perseus/src/widgets/grapher/util.tsx @@ -1,4 +1,3 @@ -/* eslint-disable one-var */ import {point as kpoint} from "@khanacademy/kmath"; import * as React from "react"; import _ from "underscore"; @@ -141,15 +140,15 @@ const Linear: LinearType = _.extend({}, PlotDefaults, { }, getFunctionForCoeffs: function (coeffs: ReadonlyArray, x: number) { - const m = coeffs[0], - b = coeffs[1]; + const m = coeffs[0]; + const b = coeffs[1]; return m * x + b; }, getEquationString: function (coords: Coords) { const coeffs: ReadonlyArray = this.getCoefficients(coords); - const m: number = coeffs[0], - b: number = coeffs[1]; + const m: number = coeffs[0]; + const b: number = coeffs[1]; return "y = " + m.toFixed(3) + "x + " + b.toFixed(3); }, }); @@ -184,9 +183,9 @@ const Quadratic: QuadraticType = _.extend({}, PlotDefaults, { coeffs: ReadonlyArray, x: number, ): number { - const a = coeffs[0], - b = coeffs[1], - c = coeffs[2]; + const a = coeffs[0]; + const b = coeffs[1]; + const c = coeffs[2]; return (a * x + b) * x + c; }, @@ -204,9 +203,9 @@ const Quadratic: QuadraticType = _.extend({}, PlotDefaults, { getEquationString: function (coords: Coords) { const coeffs = this.getCoefficients(coords); - const a = coeffs[0], - b = coeffs[1], - c = coeffs[2]; + const a = coeffs[0]; + const b = coeffs[1]; + const c = coeffs[2]; return ( "y = " + a.toFixed(3) + @@ -241,10 +240,10 @@ const Sinusoid: SinusoidType = _.extend({}, PlotDefaults, { }, getFunctionForCoeffs: function (coeffs: ReadonlyArray, x: number) { - const a = coeffs[0], - b = coeffs[1], - c = coeffs[2], - d = coeffs[3]; + const a = coeffs[0]; + const b = coeffs[1]; + const c = coeffs[2]; + const d = coeffs[3]; return a * Math.sin(b * x - c) + d; }, @@ -259,10 +258,10 @@ const Sinusoid: SinusoidType = _.extend({}, PlotDefaults, { getEquationString: function (coords: Coords) { const coeffs = this.getCoefficients(coords); - const a = coeffs[0], - b = coeffs[1], - c = coeffs[2], - d = coeffs[3]; + const a = coeffs[0]; + const b = coeffs[1]; + const c = coeffs[2]; + const d = coeffs[3]; return ( "y = " + a.toFixed(3) + @@ -307,19 +306,19 @@ const Tangent: TangentType = _.extend({}, PlotDefaults, { }, getFunctionForCoeffs: function (coeffs: ReadonlyArray, x: number) { - const a = coeffs[0], - b = coeffs[1], - c = coeffs[2], - d = coeffs[3]; + const a = coeffs[0]; + const b = coeffs[1]; + const c = coeffs[2]; + const d = coeffs[3]; return a * Math.tan(b * x - c) + d; }, getEquationString: function (coords: Coords) { const coeffs = this.getCoefficients(coords); - const a = coeffs[0], - b = coeffs[1], - c = coeffs[2], - d = coeffs[3]; + const a = coeffs[0]; + const b = coeffs[1]; + const c = coeffs[2]; + const d = coeffs[3]; return ( "y = " + a.toFixed(3) + @@ -430,9 +429,9 @@ const Exponential: ExponentialType = _.extend({}, PlotDefaults, { coeffs: ReadonlyArray, x: number, ): number { - const a = coeffs[0], - b = coeffs[1], - c = coeffs[2]; + const a = coeffs[0]; + const b = coeffs[1]; + const c = coeffs[2]; return a * Math.exp(b * x) + c; }, @@ -441,9 +440,9 @@ const Exponential: ExponentialType = _.extend({}, PlotDefaults, { return null; } const coeffs = this.getCoefficients(coords, asymptote); - const a = coeffs[0], - b = coeffs[1], - c = coeffs[2]; + const a = coeffs[0]; + const b = coeffs[1]; + const c = coeffs[2]; return ( "y = " + a.toFixed(3) + @@ -537,9 +536,9 @@ const Logarithm: LogarithmType = _.extend({}, PlotDefaults, { x: number, asymptote: Coords, ) { - const a = coeffs[0], - b = coeffs[1], - c = coeffs[2]; + const a = coeffs[0]; + const b = coeffs[1]; + const c = coeffs[2]; return a * Math.log(b * x + c); }, @@ -551,9 +550,9 @@ const Logarithm: LogarithmType = _.extend({}, PlotDefaults, { coords, asymptote, ); - const a = coeffs[0], - b = coeffs[1], - c = coeffs[2]; + const a = coeffs[0]; + const b = coeffs[1]; + const c = coeffs[2]; return ( "y = ln(" + a.toFixed(3) + @@ -597,17 +596,17 @@ const AbsoluteValue: AbsoluteValueType = _.extend({}, PlotDefaults, { }, getFunctionForCoeffs: function (coeffs: ReadonlyArray, x: number) { - const m = coeffs[0], - horizontalOffset = coeffs[1], - verticalOffset = coeffs[2]; + const m = coeffs[0]; + const horizontalOffset = coeffs[1]; + const verticalOffset = coeffs[2]; return m * Math.abs(x - horizontalOffset) + verticalOffset; }, getEquationString: function (coords: Coords) { const coeffs: ReadonlyArray = this.getCoefficients(coords); - const m = coeffs[0], - horizontalOffset = coeffs[1], - verticalOffset = coeffs[2]; + const m = coeffs[0]; + const horizontalOffset = coeffs[1]; + const verticalOffset = coeffs[2]; return ( "y = " + m.toFixed(3) + diff --git a/packages/perseus/src/widgets/orderer/orderer.tsx b/packages/perseus/src/widgets/orderer/orderer.tsx index 7324daa325..972f50fd02 100644 --- a/packages/perseus/src/widgets/orderer/orderer.tsx +++ b/packages/perseus/src/widgets/orderer/orderer.tsx @@ -1,5 +1,5 @@ /* eslint-disable @khanacademy/ts-no-error-suppressions */ -/* eslint-disable @babel/no-invalid-this, @typescript-eslint/no-unused-vars, one-var, react/no-unsafe */ +/* eslint-disable @babel/no-invalid-this, react/no-unsafe */ import {Errors} from "@khanacademy/perseus-core"; import {linterContextDefault} from "@khanacademy/perseus-linter"; import $ from "jquery"; @@ -17,12 +17,7 @@ import {getPromptJSON as _getPromptJSON} from "../../widget-ai-utils/orderer/ord import {scoreOrderer} from "./score-orderer"; import type {PerseusOrdererWidgetOptions} from "../../perseus-types"; -import type { - PerseusScore, - WidgetExports, - WidgetProps, - Widget, -} from "../../types"; +import type {WidgetExports, WidgetProps, Widget} from "../../types"; import type { PerseusOrdererRubric, PerseusOrdererUserInput, @@ -300,11 +295,6 @@ class Card extends React.Component { } } -const NORMAL = "normal"; -const AUTO = "auto"; -const HORIZONTAL = "horizontal"; -const VERTICAL = "vertical"; - type RenderProps = PerseusOrdererWidgetOptions & { current: any; }; @@ -344,8 +334,8 @@ class Orderer current: [], options: [], correctOptions: [], - height: NORMAL, - layout: HORIZONTAL, + height: "normal", + layout: "horizontal", linterContext: linterContextDefault, }; @@ -521,7 +511,7 @@ class Orderer findCorrectIndex: (arg1: any, arg2: any) => any = (draggable, list) => { // Find the correct index for a card given the current cards. - const isHorizontal = this.props.layout === HORIZONTAL; + const isHorizontal = this.props.layout === "horizontal"; // eslint-disable-next-line react/no-string-refs // @ts-expect-error - TS2769 - No overload matches this call. const $dragList = $(ReactDOM.findDOMNode(this.refs.dragList)); @@ -585,28 +575,24 @@ class Orderer return false; } - const isHorizontal = this.props.layout === HORIZONTAL, - // @ts-expect-error - TS2769 - No overload matches this call. - $draggable = $(ReactDOM.findDOMNode(draggable)), - // eslint-disable-next-line react/no-string-refs - // @ts-expect-error - TS2769 - No overload matches this call. - $bank = $(ReactDOM.findDOMNode(this.refs.bank)), - // @ts-expect-error - TS2339 - Property 'offset' does not exist on type 'JQueryStatic'. - draggableOffset = $draggable.offset(), - // @ts-expect-error - TS2339 - Property 'offset' does not exist on type 'JQueryStatic'. - bankOffset = $bank.offset(), - // @ts-expect-error - TS2339 - Property 'outerHeight' does not exist on type 'JQueryStatic'. - draggableHeight = $draggable.outerHeight(true), - // @ts-expect-error - TS2339 - Property 'outerHeight' does not exist on type 'JQueryStatic'. - bankHeight = $bank.outerHeight(true), - // @ts-expect-error - TS2339 - Property 'outerWidth' does not exist on type 'JQueryStatic'. - bankWidth = $bank.outerWidth(true), - // eslint-disable-next-line react/no-string-refs - dragList = ReactDOM.findDOMNode(this.refs.dragList), - // @ts-expect-error - TS2769 - No overload matches this call. | TS2339 - Property 'width' does not exist on type 'JQueryStatic'. - dragListWidth = $(dragList).width(), - // @ts-expect-error - TS2339 - Property 'outerWidth' does not exist on type 'JQueryStatic'. - draggableWidth = $draggable.outerWidth(true); + const isHorizontal = this.props.layout === "horizontal"; + // @ts-expect-error - TS2769 - No overload matches this call. + const $draggable = $(ReactDOM.findDOMNode(draggable)); + // eslint-disable-next-line react/no-string-refs + // @ts-expect-error - TS2769 - No overload matches this call. + const $bank = $(ReactDOM.findDOMNode(this.refs.bank)); + // @ts-expect-error - TS2339 - Property 'offset' does not exist on type 'JQueryStatic'. + const draggableOffset = $draggable.offset(); + // @ts-expect-error - TS2339 - Property 'offset' does not exist on type 'JQueryStatic'. + const bankOffset = $bank.offset(); + // @ts-expect-error - TS2339 - Property 'outerHeight' does not exist on type 'JQueryStatic'. + const draggableHeight = $draggable.outerHeight(true); + // @ts-expect-error - TS2339 - Property 'outerHeight' does not exist on type 'JQueryStatic'. + const bankHeight = $bank.outerHeight(true); + // @ts-expect-error - TS2339 - Property 'outerWidth' does not exist on type 'JQueryStatic'. + const bankWidth = $bank.outerWidth(true); + // @ts-expect-error - TS2339 - Property 'outerWidth' does not exist on type 'JQueryStatic'. + const draggableWidth = $draggable.outerWidth(true); if (isHorizontal) { return ( diff --git a/packages/simple-markdown/src/index.ts b/packages/simple-markdown/src/index.ts index 18feefe347..e4ad7187b2 100644 --- a/packages/simple-markdown/src/index.ts +++ b/packages/simple-markdown/src/index.ts @@ -1,4 +1,4 @@ -/* eslint-disable prefer-spread, no-regex-spaces, @typescript-eslint/no-unused-vars, guard-for-in, no-console, no-var */ +/* eslint-disable prefer-spread, no-regex-spaces, guard-for-in, no-console, no-var */ /** * Simple-Markdown * =============== @@ -710,7 +710,6 @@ var TABLES = (function () { // predefine regexes so we don't have to create them inside functions // sure, regex literals should be fast, even inside functions, but they // aren't in all browsers. - var TABLE_BLOCK_TRIM = /\n+/g; var TABLE_ROW_SEPARATOR_TRIM = /^ *\| *| *\| *$/g; var TABLE_CELL_END_TRIM = / *$/; var TABLE_RIGHT_ALIGN = /^ *-+: *$/; @@ -931,7 +930,7 @@ var defaultRules: DefaultRules = { // map output over the ast, except group any text // nodes together into a single string output. - for (var i = 0, key = 0; i < arr.length; i++) { + for (var i = 0; i < arr.length; i++) { var node = arr[i]; if (node.type === "text") { node = {type: "text", content: node.content}; @@ -1901,7 +1900,7 @@ var markdownToHtml = function (source: string, state?: State | null): string { // TODO: This needs definition type Props = any; -var ReactMarkdown = function (props): React.ReactElement { +var ReactMarkdown = function (props: Props): React.ReactElement { var divProps: Record = {}; for (var prop in props) {