Skip to content

Commit 5fa1e50

Browse files
committed
refactor: use eslint-config-standard-with-typescript
Also removes lint definitions that are exactly as the config.
1 parent 072ec4e commit 5fa1e50

19 files changed

+94
-63
lines changed

.eslintrc.cjs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ module.exports = {
1111
plugins: [
1212
'@typescript-eslint',
1313
],
14+
parserOptions: {
15+
project: './tsconfig.json'
16+
},
1417
extends: [
1518
// See https://github.com/standard/eslint-config-standard/blob/master/eslintrc.json
16-
'standard',
19+
'standard-with-typescript',
1720
'plugin:@typescript-eslint/eslint-recommended',
1821
'plugin:@typescript-eslint/recommended',
1922
],
2023
rules: {
2124
'array-bracket-spacing': [ 'error', 'always' ],
2225
'arrow-parens': [ 'error', 'as-needed' ],
23-
'comma-dangle': 'off',
2426
'@typescript-eslint/comma-dangle': [ 'error', 'always-multiline' ],
2527
eqeqeq: [ 'error', 'smart' ],
2628
'implicit-arrow-linebreak': [ 'error', 'beside' ],
@@ -36,28 +38,26 @@ module.exports = {
3638
alphabetize: { order: 'asc' },
3739
},
3840
],
39-
'indent': 'off',
4041
'@typescript-eslint/indent': [ 'error', 2, { MemberExpression: 'off' } ],
4142
'no-var': [ 'error' ],
42-
// Primarily to avoid false positive with interfaces declarations
43-
// See https://github.com/typescript-eslint/typescript-eslint/issues/1262
44-
'no-use-before-define': 'off',
45-
'@typescript-eslint/no-use-before-define': 'off',
4643
'nonblock-statement-body-position': [ 'error', 'beside' ],
47-
'object-curly-spacing': 'off',
48-
'@typescript-eslint/object-curly-spacing': [ 'error', 'always' ],
4944
'object-shorthand': [ 'error', 'properties' ],
5045
'prefer-arrow-callback': [ 'error' ],
51-
'prefer-const': [ 'error' ],
5246
'prefer-rest-params': 'off',
47+
48+
// TODO remove (= enable these lints and fix the issues)
5349
'@typescript-eslint/ban-ts-comment': [ 'error', {
5450
'ts-expect-error': false, // TODO: "allow-with-description",
5551
'ts-nocheck': false,
5652
} ],
57-
'@typescript-eslint/consistent-type-imports': [ 'error', { prefer: 'type-imports' } ],
53+
'@typescript-eslint/explicit-function-return-type': 'off',
5854
'@typescript-eslint/no-explicit-any': 'off',
59-
semi: 'off',
60-
'@typescript-eslint/semi': [ 'error', 'never' ],
55+
'@typescript-eslint/restrict-plus-operands': 'off',
56+
'@typescript-eslint/restrict-template-expressions': 'off',
57+
58+
// Enable when strict or strictNullChecks is enabled in tsconfig
59+
'@typescript-eslint/prefer-nullish-coalescing': 'off',
60+
'@typescript-eslint/strict-boolean-expressions': 'off',
6161
},
6262
globals: {
6363
// Mocha globals

package-lock.json

Lines changed: 29 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"@typescript-eslint/parser": "^5.49.0",
6666
"@vercel/git-hooks": "^1.0.0",
6767
"eslint": "^8.32.0",
68-
"eslint-config-standard": "^17.0.0",
68+
"eslint-config-standard-with-typescript": "^34.0.0",
6969
"eslint-plugin-import": "^2.27.5",
7070
"eslint-plugin-n": "^15.6.1",
7171
"eslint-plugin-promise": "^6.1.1",

src/helpers/simplify_sparql_results.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { SimplifiedSparqlResultMinified, SimplifiedSparqlResultRecord, SimplifiedSparqlResults, SparqlResults, SparqlValueObj, SparqlValueRaw, SparqlValueType } from '../types/sparql.js'
22

3-
export type SimplifySparqlResultsOptions = {
3+
export interface SimplifySparqlResultsOptions {
44
readonly minimize?: boolean
55
}
66

src/helpers/simplify_text_attributes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { typedEntries } from '../utils/utils.js'
22
import type { WmLanguageCode } from '../types/options.js'
33
import type { Aliases, Descriptions, Glosses, Labels, Lemmas, Representations, SimplifiedAliases, SimplifiedDescriptions, SimplifiedGlosses, SimplifiedLabels, SimplifiedLemmas, SimplifiedRepresentations } from '../types/terms.js'
44

5-
type InValue<T> = { readonly value: T }
5+
interface InValue<T> { readonly value: T }
66

77
function singleValue<V> (data: Partial<Readonly<Record<WmLanguageCode, InValue<V>>>>) {
88
const simplified: Partial<Record<WmLanguageCode, V>> = {}

src/helpers/validate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { isEntityId, isEntityPageTitle, isPropertyId, isRevisionId } from './hel
33
/** Ensure both via TypeScript and at runtime that the input value is of the expected type. Throws error when it is not */
44
function validate<T extends string> (name: string, testFn: (value: string) => value is T) {
55
return function (value: T): void {
6-
if (!testFn(value)) throw new Error(`invalid ${name}: ${value}`)
6+
if (!testFn(value)) throw new Error(`invalid ${name}: ${String(value)}`)
77
}
88
}
99

src/queries/cirrus_search.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,20 @@ export function cirrusSearchPagesFactory (buildUrl: BuildUrlFunction) {
6464
}
6565

6666
if (profile != null && typeof profile !== 'string') {
67-
throw new Error(`invalid profile: ${profile} (${typeof profile}, expected string)`)
67+
throw new Error(`invalid profile: ${String(profile)} (${typeof profile}, expected string)`)
6868
}
6969

7070
if (sort != null && typeof sort !== 'string') {
71-
throw new Error(`invalid sort: ${sort} (${typeof sort}, expected string)`)
71+
throw new Error(`invalid sort: ${String(sort)} (${typeof sort}, expected string)`)
7272
}
7373

74-
let srprop
74+
let srprop: string
7575
if (prop != null) {
7676
if (prop instanceof Array) prop = prop.join('|')
7777
if (typeof prop !== 'string') {
78-
throw new Error(`invalid prop: ${prop} (${typeof prop}, expected string)`)
78+
throw new Error(`invalid prop: ${String(prop)} (${typeof prop}, expected string)`)
7979
}
80-
srprop = prop.toString()
80+
srprop = prop
8181
}
8282

8383
return buildUrl({

src/queries/get_entities.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function getEntitiesFactory (buildUrl: BuildUrlFunction) {
2929
// Allow to pass ids as a single string
3030
ids = forceArray(ids)
3131

32-
ids.forEach(o => validate.entityId(o))
32+
ids.forEach(o => { validate.entityId(o) })
3333

3434
if (ids.length > 50) {
3535
console.warn(`getEntities accepts 50 ids max to match Wikidata API limitations:
@@ -48,6 +48,8 @@ export function getEntitiesFactory (buildUrl: BuildUrlFunction) {
4848
format,
4949
}
5050

51+
// Only specify 'no' when explictly false. Eslint ignores the fact that redirects could be undefined too.
52+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-boolean-literal-compare
5153
if (redirects === false) query.redirects = 'no'
5254

5355
if (languages) {

src/queries/get_entities_from_sitelinks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export function getEntitiesFromSitelinksFactory (buildUrl: BuildUrlFunction) {
5858
query.props = props.join('|')
5959
}
6060

61+
// Only specify 'no' when explictly false. Eslint ignores the fact that redirects could be undefined too.
62+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-boolean-literal-compare
6163
if (redirects === false) query.redirects = 'no'
6264

6365
return buildUrl(query)

src/queries/get_reverse_claims.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const getReverseClaimsFactory = (sparqlEndpoint: Url) => {
3131

3232
// Allow to request values for several properties at once
3333
properties = forceArray(properties)
34-
properties.forEach(o => validate.propertyId(o))
34+
properties.forEach(o => { validate.propertyId(o) })
3535

3636
const valueBlock = getValueBlock(values, valueFn, properties, filter)
3737
let sparql = `SELECT DISTINCT ?subject WHERE { ${valueBlock} }`

0 commit comments

Comments
 (0)