Skip to content

Commit

Permalink
wv-2579 build process eslint override removal (#4590)
Browse files Browse the repository at this point in the history
* no-undef: Removed ValueError extension & unused if statement in build process

* no-undef: Updated function args & refs to explicitly declare vars. Also updated some incorrect var names.

* no-undef: mergeConfig.js explicitly declare variable.

* no-undef: fetchPreviewSnapshots.js explicitly declare statusText variable.

* no-undef: validateConfig.js explicitly declare invalidJsonFiles[] & 'error' & removed unused layerConfigFiles[].

* no-undef: getVisMetadata.js various var declaration adjustments.

* Eliminated prefer-regex-literals from eslint in the build process & fixed the offending instance.

* .eslintrc rule removal

* Added linter counts
  • Loading branch information
Tomcariello authored Aug 25, 2023
1 parent 5630ed5 commit eb27956
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 68 deletions.
5 changes: 1 addition & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
{
"files": ["*.js"],
"rules": {
"no-undef": "off",
"n/no-unpublished-require": "off",
"no-unused-expressions": "off",
"prefer-regex-literals": "warn"
"n/no-unpublished-require": "off", // 96 failures across 79 files - many "@playwright/test" related
}
}
]
Expand Down
13 changes: 7 additions & 6 deletions tasks/build-options/extractConfigFromWMTS.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class SkipException extends Error {
* @throws {SkipException}
*/
async function main () {
for (entry of entries) {
for (const entry of entries) {
wv.layers = {}
wv.sources = {}
wvMatrixSets = {}
Expand Down Expand Up @@ -143,20 +143,21 @@ async function processEntry (entry) {
} catch (error) {
if (error instanceof SkipException) {
warningCount += 1
console.warn(`${prog}: WARNING: [${id}] Skipping\n`)
console.warn(`${prog}: WARNING: [${gcId}] Skipping\n`)
} else {
errorCount += 1
console.error(error.stack)
console.error(`${prog}: ERROR: [${gcId}:${ident}] ${e}\n`)
const ident = gcLayer['ows:Identifier']._text
console.error(`${prog}: ERROR: [${gcId}:${ident}] ${error}\n`)
}
}
}

if (gcContents.TileMatrixSet === 'Object') {
processMatrixSet(gcContents.TileMatrixSet)
processMatrixSet(gcContents.TileMatrixSet, entry)
} else {
gcContents.TileMatrixSet.forEach(gcMatrixSet => {
processMatrixSet(gcMatrixSet)
processMatrixSet(gcMatrixSet, entry)
})
}

Expand Down Expand Up @@ -278,7 +279,7 @@ async function processLayer (gcLayer, wvLayers, entry) {
}
}

function processMatrixSet (gcMatrixSet) {
function processMatrixSet (gcMatrixSet, entry) {
const tileMatrixArr = gcMatrixSet.TileMatrix
const ident = gcMatrixSet['ows:Identifier']._text
const zoomLevels = tileMatrixArr.length
Expand Down
2 changes: 1 addition & 1 deletion tasks/build-options/fetchPreviewSnapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ async function getSnapshots (layer) {
params,
responseType: 'stream'
})
let statusText
if (imageReq.status === 200) {
statusText = 'SUCCESS'
totalSuccessCount += 1
Expand All @@ -270,7 +271,6 @@ async function getSnapshots (layer) {
console.warn(`${prog}: URL: ${imageReq.config.url}`)
} catch (e) {
totalFailureCount += 1
statusText = 'ERROR'
console.error(`${prog} ERROR: Unable to fetch layer: ${wvLayerId} proj:${projection}`)
// console.error(`${prog} Error: ${e}`)
}
Expand Down
14 changes: 7 additions & 7 deletions tasks/build-options/getVisMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const daacMap = metadataConfig.daacMap || {}
const layerMetadata = {}

// These are alias or otherwise layers that don't exist in GIBS
skipLayers = [
const skipLayers = [
'Land_Water_Map',
'Land_Mask',
'World_Database_on_Protected_Areas',
Expand All @@ -80,7 +80,7 @@ skipLayers = [
]

// NOTE: Only using these properties at this time
useKeys = [
const useKeys = [
'conceptIds',
'dataCenter',
'daynight',
Expand All @@ -97,7 +97,7 @@ async function main (url) {
layerOrder = layerOrder.filter(x => !skipLayers.includes(x))

console.warn(`${prog}: Fetching ${layerOrder.length} layer-metadata files`)
for (layerId of layerOrder) {
for (const layerId of layerOrder) {
await getMetadata(layerId, url)
}

Expand All @@ -117,7 +117,7 @@ async function getDAAC (metadata) {
if (!Array.isArray(metadata.conceptIds) || !metadata.conceptIds.length) {
return metadata
}
for (collection of metadata.conceptIds) {
for (const collection of metadata.conceptIds) {
const origDataCenter = collection.dataCenter
const dataCenter = daacMap[origDataCenter]
if (!dataCenter) {
Expand All @@ -141,11 +141,11 @@ async function getMetadata (layerId, baseUrl, count) {
responseType: 'json',
timeout: 10000
}).then(async (response) => {
metadata = response.data
const metadata = response.data
layerMetadata[layerId] = await getDAAC(metadata)
metadataKeys = Object.keys(layerMetadata[layerId])
let metadataKeys = Object.keys(layerMetadata[layerId])
metadataKeys = metadataKeys.filter(x => !useKeys.includes(x))
for (key of metadataKeys) {
for (const key of metadataKeys) {
delete layerMetadata[layerId][key]
}
}).catch((error) => {
Expand Down
2 changes: 1 addition & 1 deletion tasks/build-options/mergeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function mergeFiles (inputDir) {
const data = JSON.parse(fs.readFileSync(path.join(inputDir, file), 'utf-8'))
await dictMerge(conf, data)
} else if (fs.existsSync(path.join(inputDir, file)) && fs.lstatSync(path.join(inputDir, file)).isDirectory()) {
subDir = path.join(inputDir, file)
const subDir = path.join(inputDir, file)
await mergeFiles(subDir)
}
} catch (error) {
Expand Down
12 changes: 1 addition & 11 deletions tasks/build-options/processTemporalLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ function toList (val) {
return val instanceof Array ? val : [val]
}

class ValueError extends Error {
constructor (message) {
super(message)
this.name = 'ValueError'
}
}

async function processTemporalLayer (wvLayer, value) {
const dateFormat = 'YYYY-MM-DD'
const dateTimeFormat = 'YYYY-MM-DD HH:mm:ss'
Expand Down Expand Up @@ -55,7 +48,7 @@ async function processTemporalLayer (wvLayer, value) {
endDate = moment.utc(endDate).subtract(1, 'day').format('YYYY-MM-DDTHH:mm:ss[Z]')
}
}
const regex = new RegExp(/\d+/g)
const regex = /\d+/g
const match = regex.exec(interval)
rangeInterval.push(match)
if (endDate.endsWith('T00:00:00Z')) {
Expand Down Expand Up @@ -89,9 +82,6 @@ async function processTemporalLayer (wvLayer, value) {
}
}
} catch (e) {
if (e instanceof ValueError) {
throw new Error(`Invalid time: ${range}`)
}
throw new Error(`Error processing temporal layer: ${e}`)
}
return wvLayer
Expand Down
7 changes: 3 additions & 4 deletions tasks/build-options/validateConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ const schemaRaw = fs.readFileSync(schemaFile)
const schema = JSON.parse(schemaRaw)
const validate = ajv.compile(schema)

layerConfigFiles = []
invalidJsonFiles = []
const invalidJsonFiles = []

console.warn(`${prog}: Validating layer configs...`)

async function main () {
let files = globSync(inputDirectory + '/**/*')
files = files.filter(file => file.endsWith('.json'))
for (filePath of files) {
for (const filePath of files) {
validateFile(filePath)
}
if (invalidJsonFiles.length) {
Expand All @@ -66,7 +65,7 @@ async function validateFile (filePath) {
const layer = JSON.parse(layerFile)
const valid = validate(layer)
if (!valid) {
for (error of validate.errors) {
for (const error of validate.errors) {
invalidJsonFiles.push(error)
console.error(`${prog}: ERROR: ${error.instancePath} ${error.message}`)
if (argv.mode === 'verbose') console.error(error)
Expand Down
69 changes: 35 additions & 34 deletions web/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,22 @@
For rules set to "off": consider setting to "warn" to identify non-compliance in new code
For rules set to "warn": consider removing to throw errors on existing and future code
*/

/* Error Counts compiled 8/22/2023 */

// Base rule overrides
"no-nested-ternary": "off", // 58 errors
"no-shadow": "warn", // 136 errors
"max-len": "off",
"consistent-return": "off", // 73 errors
"no-underscore-dangle": "off",
"func-names": "off",
"no-param-reassign": [ // 329 errors
"no-nested-ternary": "off", // 164 errors across 40 files
"no-shadow": "warn", // 110 errors across 40 files
"max-len": "off", // 315 errors across 109 files
"consistent-return": "off", // 95 errors across 58 files
"no-underscore-dangle": "off", // 40 errors across 7 files
"no-param-reassign": [ // 198 errors across 46 files
"warn",
{
"props": false
}
],
"no-use-before-define": [
"no-use-before-define": [ // 238 errors across 56 files
"error",
{
"functions": false,
Expand All @@ -100,21 +102,20 @@
// Import rules overrides
"import/no-cycle": "warn",
// Accesibility rules overrides
"jsx-a11y/no-noninteractive-tabindex": "off",
"jsx-a11y/no-noninteractive-element-interactions": "off",
"jsx-a11y/anchor-has-content": "off",
"jsx-a11y/control-has-associated-label": "off",
"jsx-a11y/anchor-is-valid": "off",
"jsx-a11y/label-has-associated-control": "off",
"jsx-a11y/alt-text": "off",
"jsx-a11y/mouse-events-have-key-events": "off",
"jsx-a11y/tabindex-no-positive": "off",
"jsx-a11y/no-static-element-interactions": "off",
"jsx-a11y/click-events-have-key-events": "off",
"jsx-a11y/no-noninteractive-tabindex": "off", // 2 errors across 2 files
"jsx-a11y/no-noninteractive-element-interactions": "off", // 5 errors across 5 files
"jsx-a11y/anchor-has-content": "off", // 1 error across 1 files
"jsx-a11y/control-has-associated-label": "off", // 1 error across 1 files
"jsx-a11y/anchor-is-valid": "off", // 24 errors across 13 files
"jsx-a11y/label-has-associated-control": "off", // 5 errors across 4 files
"jsx-a11y/alt-text": "off", // 15 errors across 10 files
"jsx-a11y/mouse-events-have-key-events": "off", // 7 errors across 4 files
"jsx-a11y/no-static-element-interactions": "off", // 71 errors across 39 files
"jsx-a11y/click-events-have-key-events": "off", // 70 errors across 39 files
// React rules overrides
"react/jsx-props-no-spreading": "warn", // 17 errors
"react/jsx-filename-extension": "off",
"react/jsx-no-bind": "warn",
"react/jsx-props-no-spreading": "warn", // 6 errors across 2 files
"react/jsx-filename-extension": "off", // 206 errors across 206 files
"react/jsx-no-bind": "warn", // 9 errors across 5 files
"react/sort-comp": [
"error",
{
Expand Down Expand Up @@ -155,18 +156,18 @@
}
}
],
"react/forbid-prop-types": "off", // 216 errors
"react/require-default-props": "off", // 965 errors,
"class-methods-use-this": "warn",
"react/no-unused-class-component-methods": "warn",
"react/no-unknown-property": "warn",
"react/jsx-no-useless-fragment": "warn",
"react/no-unstable-nested-components": "warn",
"react/prop-types": "warn",
"react/no-unused-prop-types": "warn",
"default-param-last": "warn",
"prefer-regex-literals": "warn",
"no-promise-executor-return": "warn"
"react/forbid-prop-types": "off", // 411 errors across 139 files
"react/require-default-props": "off", // 1644 errors across > 80 files
"class-methods-use-this": "warn", // 15 errors across 13 files
"react/no-unused-class-component-methods": "warn", // 8 errors across 7 files
"react/no-unknown-property": "warn", // 2 errors across 2 files
"react/jsx-no-useless-fragment": "warn", // 3 errors across 3 files
"react/no-unstable-nested-components": "warn", // 1 error across 1 file
"react/prop-types": "warn", // 58 errors across 22 files
"react/no-unused-prop-types": "warn", // 9 errors across 9 files
"default-param-last": "warn", // 42 errors across 34 files
"prefer-regex-literals": "warn", // 3 errors across 1 file
"no-promise-executor-return": "warn" // 1 error across 1 file
}
}
]
Expand Down

0 comments on commit eb27956

Please sign in to comment.