Skip to content

Commit

Permalink
chore(W-17692101): eslint 9 (#730)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley authored Jan 29, 2025
1 parent a37af21 commit dcb6df6
Show file tree
Hide file tree
Showing 12 changed files with 581 additions and 291 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

3 changes: 0 additions & 3 deletions .eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion bin/dev.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning
// eslint-disable-next-line node/shebang

async function main() {
const {execute} = await import('@oclif/core')
await execute({development: true, dir: import.meta.url})
Expand Down
1 change: 0 additions & 1 deletion bin/run.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env node

// eslint-disable-next-line node/shebang
async function main() {
const {execute} = await import('@oclif/core')
await execute({dir: import.meta.url})
Expand Down
19 changes: 19 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {includeIgnoreFile} from '@eslint/compat'
import oclif from 'eslint-config-oclif'
import prettier from 'eslint-config-prettier'
import path from 'node:path'
import {fileURLToPath} from 'node:url'

const gitignorePath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '.gitignore')

export default [
includeIgnoreFile(gitignorePath),
...oclif,
prettier,
{
files: ['test/**/*.ts'],
rules: {
'import/no-named-as-default-member': 'off',
},
},
]
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"devDependencies": {
"@commitlint/config-conventional": "^19",
"@eslint/compat": "^1.2.5",
"@oclif/plugin-help": "^6",
"@oclif/prettier-config": "^0.2.1",
"@oclif/test": "^4",
Expand All @@ -30,10 +31,9 @@
"@types/sinon": "^17.0.3",
"chai": "^4",
"commitlint": "^19",
"eslint": "^8.57.1",
"eslint-config-oclif": "^5.2.2",
"eslint-config-oclif-typescript": "^3.1.13",
"eslint-config-prettier": "^9.1.0",
"eslint": "^9.19.0",
"eslint-config-oclif": "^6.0.0",
"eslint-config-prettier": "^10.0.1",
"husky": "^9.1.7",
"lint-staged": "^15.4.2",
"mocha": "^10.8.2",
Expand Down Expand Up @@ -81,7 +81,7 @@
"build": "shx rm -rf lib && tsc",
"clean": "shx rm -f oclif.manifest.json",
"compile": "tsc",
"lint": "eslint . --ext .ts",
"lint": "eslint",
"postpack": "yarn run clean",
"posttest": "yarn lint",
"prepack": "yarn build && oclif manifest && oclif readme",
Expand Down
21 changes: 11 additions & 10 deletions src/commands/schema/compare.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {Flags, toConfiguredId} from '@oclif/core'
import {bold, cyan, underline} from 'ansis'
import {Operation, diff} from 'just-diff'
import {diff, Operation} from 'just-diff'
import get from 'lodash.get'
import fs from 'node:fs'
import path from 'node:path'
import * as semver from 'semver'
import {Schema} from 'ts-json-schema-generator'

import SnapshotCommand from '../../snapshot-command.js'
import {GLOB_PATTERNS, getAllFiles, getKeyNameFromFilename} from '../../util.js'
import {getAllFiles, getKeyNameFromFilename, GLOB_PATTERNS} from '../../util.js'
import {SchemaGenerator, Schemas} from './generate.js'

export type SchemaComparison = Array<{op: Operation; path: (number | string)[]; value: unknown}>
Expand All @@ -31,6 +31,7 @@ export default class SchemaCompare extends SnapshotCommand {
}),
}

// eslint-disable-next-line complexity
public async run(): Promise<SchemaComparison> {
const strategy =
typeof this.config.pjson.oclif?.commands === 'string' ? 'pattern' : this.config.pjson.oclif?.commands?.strategy
Expand Down Expand Up @@ -86,13 +87,6 @@ export default class SchemaCompare extends SnapshotCommand {
const basePath = lastElementIsNum ? readablePath.replace(`.${lastPathElement}`, '') : readablePath

switch (change.op) {
case 'replace': {
humanReadableChanges[commandId].push(
`${underline(readablePath)} was changed from ${cyan(existing)} to ${cyan(latest)}`,
)
break
}

case 'add': {
humanReadableChanges[commandId].push(
lastElementIsNum
Expand All @@ -111,6 +105,13 @@ export default class SchemaCompare extends SnapshotCommand {
break
}

case 'replace': {
humanReadableChanges[commandId].push(
`${underline(readablePath)} was changed from ${cyan(existing)} to ${cyan(latest)}`,
)
break
}

default: {
break
}
Expand All @@ -133,7 +134,7 @@ export default class SchemaCompare extends SnapshotCommand {
}

this.log()
const bin = process.platform === 'win32' ? 'bin\\dev.cmd' : 'bin/dev.js'
const bin = process.platform === 'win32' ? String.raw`bin\dev.cmd` : 'bin/dev.js'
this.log(
'If intended, please update the schema file(s) and run again:',
bold(`${bin} ${toConfiguredId('schema:generate', this.config)}`),
Expand Down
4 changes: 2 additions & 2 deletions src/commands/schema/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {red} from 'ansis'
import {globbySync} from 'globby'
import fs from 'node:fs'
import path from 'node:path'
import {Schema, createGenerator} from 'ts-json-schema-generator'
import {createGenerator, Schema} from 'ts-json-schema-generator'

import SnapshotCommand from '../../snapshot-command.js'
import {GLOB_PATTERNS, getAllFiles, getSchemaFileName} from '../../util.js'
import {getAllFiles, getSchemaFileName, GLOB_PATTERNS} from '../../util.js'

export type SchemasMap = {
[key: string]: Schema
Expand Down
6 changes: 3 additions & 3 deletions src/commands/snapshot/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ interface Change {
removed?: boolean
}

type CommandChange = {
type CommandChange = Change & {
alias: Change[]
chars: Change[]
flags: Change[]
plugin: string
} & Change
}

export type CompareResponse = {
addedCommands?: string[]
Expand Down Expand Up @@ -153,7 +153,7 @@ export default class Compare extends SnapshotCommand {

/**
* compares two command's properties to each other
* @return a list of added, removed, updated, and changed properties
* @returns a list of added, removed, updated, and changed properties
* @param initial initial command property to compare against
* @param updated generated command property to compare with
*/
Expand Down
2 changes: 1 addition & 1 deletion src/commands/snapshot/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class Generate extends SnapshotCommand {
const charConflictCommand = resultCommands.find(
(command) =>
command.flags.length > 1 &&
new Set([...command.flags, ...command.flagChars, ...command.flagAliases]).size !==
new Set([...command.flagAliases, ...command.flagChars, ...command.flags]).size !==
[...command.flags, ...command.flagChars, ...command.flagAliases].length,
)

Expand Down
9 changes: 9 additions & 0 deletions test/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,41 @@ describe('util test', () => {
it('should return correct command id when only hyphens in file name a-b-c.json', () => {
expect(getKeyNameFromFilename('a-b-c.json')).to.equal('a:b:c')
})

it('should return correct command id when escaped hyphens in file name a-b-c__d.json', () => {
expect(getKeyNameFromFilename('a-b-c__d.json')).to.equal('a:b:c-d')
})

it('should return correct command id when escaped hyphens in file name a__b-c__d.json', () => {
expect(getKeyNameFromFilename('a__b-c__d.json')).to.equal('a-b:c-d')
})

it('should return correct command id when escaped hyphens in file name a-b__c__d.json', () => {
expect(getKeyNameFromFilename('a-b__c__d.json')).to.equal('a:b-c-d')
})

it('should return correct command id when underscore in file name a-b-c_d.json', () => {
expect(getKeyNameFromFilename('a-b-c_d.json')).to.equal('a:b:c_d')
})
})

describe('getSchemaFileName', () => {
it('should return correct file name when only ":" in command id a:b:c', () => {
expect(getSchemaFileName('a:b:c')).to.equal('a-b-c.json')
})

it('should return correct file name when hyphens in command id a:b:c-d', () => {
expect(getSchemaFileName('a:b:c-d')).to.equal('a-b-c__d.json')
})

it('should return correct file name when hyphens in command id a-b:c-d', () => {
expect(getSchemaFileName('a-b:c-d')).to.equal('a__b-c__d.json')
})

it('should return correct file name when hyphens in command id a:b-c-d', () => {
expect(getSchemaFileName('a:b-c-d')).to.equal('a-b__c__d.json')
})

it('should return correct file name when underscore in command id a:b:c_d', () => {
expect(getSchemaFileName('a:b:c_d')).to.equal('a-b-c_d.json')
})
Expand Down
Loading

0 comments on commit dcb6df6

Please sign in to comment.