Skip to content

Commit

Permalink
Resolve or disable misc eslint errors
Browse files Browse the repository at this point in the history
Test plan:
    - All existing tests pass

flag=none

Refs DE-1426

Change-Id: I9b07240ff53489f8cbdd7f09f9188ceaa592580c
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/303743
Tested-by: Service Cloud Jenkins <[email protected]>
Reviewed-by: Dustin Cowles <[email protected]>
Reviewed-by: Kai Bjorkman <[email protected]>
QA-Review: Aaron Shafovaloff <[email protected]>
Product-Review: Cameron Ray <[email protected]>
  • Loading branch information
aaronshaf committed Oct 21, 2022
1 parent 65d2e79 commit 1286afe
Show file tree
Hide file tree
Showing 27 changed files with 71 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ import '../../../ext/custom_moment_locales/sl'
import $ from '@canvas/datetime'
import * as configureDateTime from '../configureDateTime'
import * as configureDateTimeMomentParser from '../configureDateTimeMomentParser'
// eslint-disable-next-line import/no-nodejs-modules
import fs from 'fs'
import I18n, {useTranslations} from '@canvas/i18n'
// eslint-disable-next-line import/no-nodejs-modules
import path from 'path'
import YAML from 'yaml'
import {parse, format, hasMeridiem} from 'datetime'
Expand Down
2 changes: 1 addition & 1 deletion ui/boot/initializers/enableHelpDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {useScope as useI18nScope} from '@canvas/i18n'
import helpDialogTemplate from './jst/helpDialog.handlebars'
import $ from 'jquery'
import _ from 'underscore'
import INST from 'browser-sniffer'
import 'browser-sniffer'
import htmlEscape from 'html-escape'
import preventDefault from 'prevent-default'
import '@canvas/jquery/jquery.instructure_misc_helpers'
Expand Down
1 change: 0 additions & 1 deletion ui/ext/custom_timezone_locales/th_TH.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

// eslint-disable-next-line import/no-commonjs
module.exports = {
name: 'th_TH',
day: {
Expand Down
1 change: 1 addition & 0 deletions ui/features/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import ready from '@instructure/ready'

import '@canvas/rails-flash-notifications'
import '@canvas/jquery/jquery.disableWhileLoading'
// eslint-disable-next-line import/no-named-as-default
import DashboardHeader from './react/DashboardHeader'

ready(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export default class SideCommentDiscussionTopic extends MaterializedDiscussionTo
parse() {
super.parse(...arguments)

for (var entry of this.data.entries) {
for (const entry of this.data.entries) {
entry.replies = []
}

for (const id in this.flattened) {
entry = this.flattened[id]
const entry = this.flattened[id]
if (entry.root_entry_id) {
delete entry.replies
const parent = this.flattened[entry.root_entry_id]
Expand All @@ -41,7 +41,7 @@ export default class SideCommentDiscussionTopic extends MaterializedDiscussionTo
}
}

for (entry of this.data.entries) {
for (const entry of this.data.entries) {
entry.replies.sort((a, b) => Date.parse(b.created_at) - Date.parse(a.created_at))

if (ENV.DISCUSSION.SORT_BY_RATING) {
Expand Down
1 change: 1 addition & 0 deletions ui/features/k5_course/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
import React from 'react'
import ReactDOM from 'react-dom'
// eslint-disable-next-line import/no-named-as-default
import K5Course from './react/K5Course'
import k5Theme from '@canvas/k5/react/k5-theme'
import ready from '@instructure/ready'
Expand Down
2 changes: 0 additions & 2 deletions ui/features/k5_dashboard/react/GradesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,5 +264,3 @@ GradesPage.propTypes = {
avatar_image_url: PropTypes.string,
}).isRequired,
}

export default GradesPage
6 changes: 3 additions & 3 deletions ui/features/k5_dashboard/react/K5Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ import {Tray} from '@instructure/ui-tray'
import {View} from '@instructure/ui-view'

import K5Tabs, {scrollElementIntoViewIfCoveredByHeader} from '@canvas/k5/react/K5Tabs'
import GradesPage from './GradesPage'
import {GradesPage} from './GradesPage'
import HomeroomPage from './HomeroomPage'
import TodosPage from './TodosPage'
import {TodosPage} from './TodosPage'
import K5DashboardContext from '@canvas/k5/react/K5DashboardContext'
import {CardDashboardLoader} from '@canvas/dashboard-card'
import {mapStateToProps} from '@canvas/k5/redux/redux-helpers'
Expand Down Expand Up @@ -141,7 +141,7 @@ const getWindowSize = () => ({
height: window.innerHeight,
})

export const K5Dashboard = ({
const K5Dashboard = ({
assignmentsDueToday,
assignmentsMissing,
assignmentsCompletedForToday,
Expand Down
2 changes: 0 additions & 2 deletions ui/features/k5_dashboard/react/TodosPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,3 @@ TodosPage.propTypes = {
visible: PropTypes.bool.isRequired,
openTodosInNewTab: PropTypes.bool.isRequired,
}

export default TodosPage
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import React from 'react'
import {act, render, waitFor} from '@testing-library/react'

import GradesPage, {getGradingPeriodsFromCourses, overrideCourseGradingPeriods} from '../GradesPage'
import {GradesPage, getGradingPeriodsFromCourses, overrideCourseGradingPeriods} from '../GradesPage'
import fetchMock from 'fetch-mock'

jest.mock('@canvas/k5/react/utils')
Expand Down
2 changes: 1 addition & 1 deletion ui/features/k5_dashboard/react/__tests__/TodosPage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import fetchMock from 'fetch-mock'
import {destroyContainer} from '@canvas/alerts/react/FlashAlert'

import {MOCK_TODOS} from './mocks'
import TodosPage, {sortTodos} from '../TodosPage'
import {TodosPage, sortTodos} from '../TodosPage'

const FETCH_TODOS_URL = /\/api\/v1\/users\/self\/todo.*/

Expand Down
6 changes: 4 additions & 2 deletions ui/features/manage_avatars/jquery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ $(document).ready(function () {
event.preventDefault()
const $link = $(this)
if ($link.attr('data-state') === 'none') {
var result = window.confirm(
// eslint-disable-next-line no-alert
const result = window.confirm(
I18n.t('prompts.delete_avatar', "Are you sure you want to delete this user's profile pic?")
)
if (!result) {
return
}
} else if ($link.attr('data-state') === 'locked') {
var result = window.confirm(
// eslint-disable-next-line no-alert
const result = window.confirm(
I18n.t(
'prompts.lock_avatar',
'Locking this picture will approve it and prevent the user from updating it. Continue?'
Expand Down
2 changes: 2 additions & 0 deletions ui/features/media_player_iframe_content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import React from 'react'
import ReactDOM from 'react-dom'
// TODO: use URL() in browser to parse URL
// eslint-disable-next-line import/no-nodejs-modules
import {parse} from 'url'
import ready from '@instructure/ready'
import CanvasMediaPlayer from '@canvas/canvas-media-player'
Expand Down
4 changes: 2 additions & 2 deletions ui/features/quiz_statistics/stores/__tests__/reports.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ describe('quizReports:generate', function () {
by: 1,
})

assertChange({
return assertChange({
fn: () => Dispatcher.dispatch('quizReports:generate', 'student_analysis'),
of: () => fakeServer.requests.length,
by: 0,
Expand All @@ -387,7 +387,7 @@ describe('quizReports:generate', function () {
],
})

assertChange({
return assertChange({
fn: () => Dispatcher.dispatch('quizReports:generate', 'student_analysis'),
of: () => fakeServer.requests.length,
by: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import {useScope as useI18nScope} from '@canvas/i18n'
import React from 'react'
import PropTypes from 'prop-types'
import shapes from './shapes'
import {duplicatesShape, missingsShape} from './shapes'
import DuplicateSection from './duplicate_section'
import MissingPeopleSection from './missing_people_section'
import {Alert} from '@instructure/ui-alerts'
Expand All @@ -30,8 +30,8 @@ class PeopleValidationIssues extends React.Component {
static propTypes = {
searchType: PropTypes.string.isRequired,
inviteUsersURL: PropTypes.string,
duplicates: PropTypes.shape(shapes.duplicatesShape),
missing: PropTypes.shape(shapes.missingsShape),
duplicates: PropTypes.shape(duplicatesShape),
missing: PropTypes.shape(missingsShape),
onChangeDuplicate: PropTypes.func.isRequired,
onChangeMissing: PropTypes.func.isRequired,
}
Expand All @@ -49,7 +49,6 @@ class PeopleValidationIssues extends React.Component {
super(props)

this.state = {
newUsersForMissing: {},
focusElem: null,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const TEN_E_8 = 10e8
// stack overflow suggests this implementation
export const isNumeric = n => {
n = numberHelper.parse(n)
return !isNaN(n) && isFinite(n) // eslint-disable-line no-restricted-globals
return !Number.isNaN(Number(n)) && Number.isFinite(Number(n))
}

const haveGradingScheme = assignment => {
Expand Down
2 changes: 1 addition & 1 deletion ui/shared/conditional-release-editor/react/validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const isNumeric = n => {
} catch (e) {
return false
}
return !isNaN(n) && isFinite(n) // eslint-disable-line no-restricted-globals
return !Number.isNaN(Number(n)) && Number.isFinite(Number(n))
}

const checkBlank = s => {
Expand Down
4 changes: 2 additions & 2 deletions ui/shared/conditional-release-score/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const I18n = useI18nScope('cyoe_assignment_sidebar_score')
// stack overflow suggests this implementation
const isNumeric = n => {
const parsed = numberHelper.parse(n)
return !isNaN(parsed) && isFinite(parsed)
return !Number.isNaN(Number(parsed)) && Number.isFinite(Number(parsed))
}

const haveGradingScheme = assignment => (assignment ? !!assignment.grading_scheme : false)
Expand Down Expand Up @@ -125,7 +125,7 @@ export const i18nGrade = (grade, assignment) => {
assignment.grading_type !== GradingTypes.gpa_scale.key
) {
const number = numberHelper.parse(grade.replace(/%$/, ''))
if (!isNaN(number)) {
if (!Number.isNaN(Number(number))) {
return formatScore(number, assignment)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ describe('processSingleContentItem', () => {
})

it('extracts the first content item', () => {
processSingleContentItem({data: data()}).then(result => {
return processSingleContentItem({data: data()}).then(result => {
expect(result).toEqual(content_items[0])
})
})

describe('when no content items are provided', () => {
it('returns "undefined"', () => {
processSingleContentItem({data: data({content_items: []})}).then(result => {
return processSingleContentItem({data: data({content_items: []})}).then(result => {
expect(result).toBeUndefined()
})
})
Expand Down
32 changes: 18 additions & 14 deletions ui/shared/forms/jquery/jquery.instructure_forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ $.ajaxJSONPreparedFiles = function (options) {
parameters.no_redirect = true
file = file.files[0]
import('@canvas/upload-file')
.then(({uploadFile}) =>
uploadFile(uploadUrl, parameters, file, undefined, options.onProgress)
.then(({uploadFile: uploadFile_}) =>
uploadFile_(uploadUrl, parameters, file, undefined, options.onProgress)
)
.then(data => {
attachments.push(data)
Expand Down Expand Up @@ -456,6 +456,7 @@ $.httpSuccess = function (r) {
(!r.status && window.location.protocol === 'file:') ||
(r.status >= 200 && r.status < 300) ||
r.status === 304 ||
// eslint-disable-next-line eqeqeq
($.browser.safari && r.status == undefined)
)
} catch (e) {
Expand Down Expand Up @@ -533,6 +534,7 @@ $.sendFormAsBinary = function (options, not_binary) {
if (not_binary) {
xhr.send(body)
} else if (!xhr.sendAsBinary) {
// eslint-disable-next-line no-console
console.log('xhr.sendAsBinary not supported')
} else {
xhr.sendAsBinary(body)
Expand Down Expand Up @@ -611,6 +613,7 @@ $.toMultipartForm = function (params, callback) {
'Content-Type: multipart/mixed; boundary=' +
innerBoundary +
'\r\n\r\n'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
for (const _jdx in value) {
fileList.push(value)
}
Expand Down Expand Up @@ -733,6 +736,7 @@ $.fn.fillFormData = function (data, opts) {
val = ''
}
$obj.val(val.toString())
// eslint-disable-next-line eqeqeq
} else if ($obj.val() == data[name]) {
$obj.attr('checked', true)
} else {
Expand Down Expand Up @@ -780,11 +784,10 @@ $.fn.getFormData = function (options) {
const multiValue = attr.match(/\[\]$/)
if (inputType === 'hidden' && !multiValue) {
if (
$form
.find("[name='" + attr + "']")
.filter(
'textarea,:radio:checked,:checkbox:checked,:text,:password,select,:hidden'
)[0] != $input[0]
$form.find("[name='" + attr + "']").filter(
'textarea,:radio:checked,:checkbox:checked,:text,:password,select,:hidden'
// eslint-disable-next-line eqeqeq
)[0] != $input[0]
) {
return
}
Expand Down Expand Up @@ -993,6 +996,7 @@ $.fn.validateForm = function (options) {
})
}
let hasErrors = false
// eslint-disable-next-line @typescript-eslint/no-unused-vars
for (const _err in errors) {
hasErrors = true
break
Expand Down Expand Up @@ -1028,13 +1032,13 @@ $.fn.formErrors = function (data_errors, options) {
val = newval
} else if (
typeof i === 'number' &&
val.length == 2 &&
val.length === 2 &&
val[0] instanceof $ &&
typeof val[1] === 'string'
) {
elementErrors.push(val)
return
} else if (typeof i === 'number' && val.length == 2 && typeof val[1] === 'string') {
} else if (typeof i === 'number' && val.length === 2 && typeof val[1] === 'string') {
newval = []
newval.push(val[1])
i = val[0]
Expand Down Expand Up @@ -1262,12 +1266,12 @@ $.fn.hideErrors = function (_options) {
this.data('associated_error_box', null)
}
this.find(':input').each(function () {
const $obj = $(this),
$oldBox = $obj.data('associated_error_box')
if ($oldBox) {
$oldBox.remove()
const $obj = $(this)
const $oldBox_ = $obj.data('associated_error_box')
if ($oldBox_) {
$oldBox_.remove()
$obj.data('associated_error_box', null)
const srError = _.find($screenReaderErrors, node => $(node).text() === $oldBox.text())
const srError = _.find($screenReaderErrors, node => $(node).text() === $oldBox_.text())
if (srError) {
$(srError).remove()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,12 @@ export default class NaiveFetchDispatch {
*/
request.active = true

/* eslint-disable promise/catch-or-return */
fetch(...args)
.then(request.resolve)
.catch(request.reject)
.finally(() => {
this.clearRequest(request)
})
/* eslint-enable promise/catch-or-return */
}

this.addRequest(request)
Expand Down
2 changes: 2 additions & 0 deletions ui/shared/instui-bindings/react/AsyncSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const I18n = useI18nScope('canvas_async_search_selesct')
const noOptionsId = '~~empty-option~~'

const {Option} = Select as any
// eslint-disable-next-line react/forbid-foreign-prop-types
const {propTypes: selectPropTypes} = Select as any

CanvasAsyncSelect.Option = Option
Expand All @@ -52,6 +53,7 @@ CanvasAsyncSelect.propTypes = {
}

export default function CanvasAsyncSelect({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
options = [],
inputValue,
isLoading = false,
Expand Down
1 change: 1 addition & 0 deletions ui/shared/instui-bindings/react/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class CanvasSelect extends React.Component<Props, State> {
}

render(): ReactElement {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const {id, label, value, onChange, children, noOptionsLabel = '---', ...otherProps} = this.props

return (
Expand Down
Loading

0 comments on commit 1286afe

Please sign in to comment.