Skip to content

Commit

Permalink
Merge pull request #129 from EdJoPaTo/stricter-checks
Browse files Browse the repository at this point in the history
refactor: stricter eslint and ts config
  • Loading branch information
maxlath committed Mar 3, 2024
2 parents 2aeed2c + 97a234b commit aee0b1e
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = {
'prefer-const': [ 'error' ],
'prefer-rest-params': 'off',
'@typescript-eslint/ban-ts-comment': [ 'error', {
'ts-expect-error': false, // TODO: "allow-with-description",
'ts-expect-error': "allow-with-description",
'ts-nocheck': false,
} ],
'@typescript-eslint/consistent-type-imports': [ 'error', { prefer: 'type-imports' } ],
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/simplify_entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const simplifyIfDefined = (entity, simplified, attribute, options?) => {
}

export const simplifyEntities = (entities: Entities, options: SimplifyEntityOptions = {}) => {
// @ts-expect-error
// @ts-expect-error support downloaded json directly
if (entities.entities) entities = entities.entities
const { entityPrefix } = options

Expand Down
6 changes: 3 additions & 3 deletions tests/get_entities_from_sitelinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const getEntitiesFromSitelinks = getEntitiesFromSitelinksFactory(buildUrl)
describe('getEntitiesFromSitelinks', () => {
describe('polymorphism', () => {
it('rejects parameters as multiple arguments', () => {
// @ts-expect-error
// @ts-expect-error old usage
should(() => getEntitiesFromSitelinks('Lyon')).throw()
// @ts-expect-error
// @ts-expect-error old usage
should(() => getEntitiesFromSitelinks('Lyon', 'en')).throw()
})
})
Expand Down Expand Up @@ -51,7 +51,7 @@ describe('getEntitiesFromSitelinks', () => {
})

it('converts 2-letters language codes to Wikipedia sites', () => {
// @ts-expect-error
// @ts-expect-error 2-letter language codes are not sites
const query = parseUrlQuery(getEntitiesFromSitelinks({ titles: 'Lyon', sites: [ 'it', 'fr' ] }))
should(query.sites).equal('itwiki|frwiki')
})
Expand Down
4 changes: 2 additions & 2 deletions tests/get_entity_revision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ const getEntityRevision = getEntityRevisionFactory(instance, wgScriptPath)

describe('getEntityRevision', () => {
it('should reject an invalid entity id', () => {
// @ts-expect-error
// @ts-expect-error not an entity id
should(() => getEntityRevision({ id: '3548931' })).throw('invalid entity id: 3548931 (type: string)')
})

it('should reject an invalid revision', () => {
// @ts-expect-error
// @ts-expect-error not a valid revision
should(() => getEntityRevision({ id: 'Q123', revision: 'foo' })).throw('invalid revision id: foo (type: string)')
})

Expand Down
2 changes: 1 addition & 1 deletion tests/get_many_entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('wikidata getManyEntities', () => {

describe('polymorphism', () => {
it('should reject parameters as multiple arguments', () => {
// @ts-expect-error
// @ts-expect-error old syntax
should(() => getManyEntities(manyIds, 'fr', 'info', 'json')).throw()
})

Expand Down
2 changes: 1 addition & 1 deletion tests/get_reverse_claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('getReverseClaims', () => {
})

it('should reject invalid property ids', () => {
// @ts-expect-error
// @ts-expect-error invalid property id
should(() => getReverseClaims({ properties: 'foo', values: 'Q535' })).throw('invalid property id: foo (type: string)')
})

Expand Down
2 changes: 1 addition & 1 deletion tests/get_revisions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const getRevisions = getRevisionsFactory(buildUrl)

describe('getRevisions', () => {
it('should reject invalid ids', () => {
// @ts-expect-error
// @ts-expect-error invalid revision id
should(() => getRevisions({ ids: 'foo' })).throw('invalid entity page title: foo (type: string)')
})

Expand Down
6 changes: 3 additions & 3 deletions tests/rank.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cloneDeep } from 'lodash-es'
import should from 'should'
import { truthyClaims, truthyPropertyClaims } from '../src/helpers/rank.js'
import { readJsonFile } from './lib/utils.js'
import { assert, readJsonFile } from './lib/utils.js'
import type { Item } from '../src/types/entity.js'

const Q4115189 = readJsonFile('./tests/data/Q4115189.json') as Item
Expand All @@ -12,7 +12,7 @@ describe('truthyClaims', () => {
should(Q4115189Claims.P135.length).equal(3)
const truthyOnly = truthyClaims(Q4115189Claims)
should(truthyOnly.P135.length).equal(1)
// @ts-expect-error
assert(truthyOnly.P135[0].mainsnak.datavalue.type === 'wikibase-entityid')
should(truthyOnly.P135[0].mainsnak.datavalue.value.id).equal('Q2044250')
})
})
Expand All @@ -23,7 +23,7 @@ describe('truthyPropertyClaims', () => {
should(Q4115189Claims.P135.length).equal(3)
const truthyOnly = truthyPropertyClaims(Q4115189Claims.P135)
should(truthyOnly.length).equal(1)
// @ts-expect-error
assert(truthyOnly[0].mainsnak.datavalue.type === 'wikibase-entityid')
should(truthyOnly[0].mainsnak.datavalue.value.id).equal('Q2044250')
})
})
2 changes: 1 addition & 1 deletion tests/search_entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('searchEntities', () => {
})

it('should reject an invalid type parameter', () => {
// @ts-expect-error
// @ts-expect-error invalid type parameter
should(() => searchEntities({ search: 'alphabet', type: 'foo' })).throw()
})
})
Expand Down
3 changes: 2 additions & 1 deletion tests/simplify_sparql_results.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-nocheck
import { cloneDeep } from 'lodash-es'
import should from 'should'
import { isEntityId, isGuid } from '../src/helpers/helpers.js'
Expand Down Expand Up @@ -103,6 +102,7 @@ describe('wikidata simplify SPARQL results', () => {

it('should work without labels', () => {
const rawResults = cloneDeep(resultsWithLabelsDescriptionsAndAliases)
// @ts-expect-error write to readonly but its cloned testdata
rawResults.head.vars = rawResults.head.vars
.filter(varName => varName !== 'itemLabel')
const results = simplifySparqlResults(rawResults)
Expand All @@ -119,6 +119,7 @@ describe('wikidata simplify SPARQL results', () => {

it("should be ignored when the associated variable isn't selected", () => {
const rawResults = cloneDeep(resultsWithLabelsDescriptionsAndAliases)
// @ts-expect-error write to readonly but its cloned testdata
rawResults.head.vars = rawResults.head.vars
.filter(varName => varName !== 'item')
const results = simplifySparqlResults(rawResults)
Expand Down
4 changes: 2 additions & 2 deletions tests/sitelinks_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ describe('getSitelinkUrl', () => {
})

it('should reject invalid sitelinks', () => {
// @ts-expect-error
// @ts-expect-error invalid site
should(() => getSitelinkUrl({ site: 'frperlinpinpin', title: 'Lyon' })).throw()
// @ts-expect-error
// @ts-expect-error invalid site
should(() => getSitelinkUrl({ site: 'frwikiwiki', title: 'Lyon' })).throw()
})

Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"alwaysStrict": true,
// "noImplicitAny": true,
"noImplicitThis": true,
// "strictBindCallApply": true,
"strictFunctionTypes": true
"strictBindCallApply": true,
"strictFunctionTypes": true,
// "strictNullChecks": true,
// "strictPropertyInitialization": true,
// "useUnknownInCatchVariables": true,
Expand Down

0 comments on commit aee0b1e

Please sign in to comment.