Add linting

This commit is contained in:
John J. Camilleri
2021-10-04 15:26:50 +02:00
parent 1f72ef77c4
commit 634508eaa8
6 changed files with 908 additions and 13 deletions

View File

@@ -0,0 +1,2 @@
node_modules
dist

View File

@@ -0,0 +1,11 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
]
}

View File

@@ -35,7 +35,7 @@ const PgfItor = Struct({
const PgfItorPtr = ref.refType(PgfItor) const PgfItorPtr = ref.refType(PgfItor)
const PgfType = ref.types.void // TODO const PgfType = ref.types.void // TODO
const PgfTypePtr = ref.refType(PgfType) // const PgfTypePtr = ref.refType(PgfType)
const PgfTypeHypo = ref.types.void // TODO const PgfTypeHypo = ref.types.void // TODO
const PgfTypeHypoPtr = ref.refType(PgfTypeHypo) const PgfTypeHypoPtr = ref.refType(PgfTypeHypo)
@@ -58,7 +58,7 @@ const PgfMarshallerPtr = ref.refType(PgfMarshaller)
// Type definitions for `ref` package don't include extensions to Buffer // Type definitions for `ref` package don't include extensions to Buffer
interface Pointer extends Buffer { interface Pointer extends Buffer {
deref(): any deref (): any // eslint-disable-line @typescript-eslint/no-explicit-any
} }
class PGFError extends Error { class PGFError extends Error {
@@ -123,10 +123,10 @@ function handleError (errPtr: Pointer): void {
case 0: return case 0: return
// PGF_EXN_SYSTEM_ERROR // PGF_EXN_SYSTEM_ERROR
case 1: case 1: {
const desc = errno.lookup(err.code) const desc = errno.lookup(err.code)
throw new Error(`${desc}: ${err.msg}`) throw new Error(`${desc}: ${err.msg}`)
}
// PGF_EXN_PGF_ERROR // PGF_EXN_PGF_ERROR
case 2: case 2:
throw new PGFError(err.msg) throw new PGFError(err.msg)
@@ -159,21 +159,21 @@ export class PGFGrammar {
} }
// NB the library user is responsible for calling this // NB the library user is responsible for calling this
release () { release (): void {
runtime.pgf_free_revision(this.db, this.revision) runtime.pgf_free_revision(this.db, this.revision)
} }
getAbstractName () { getAbstractName (): string {
const err = ref.alloc(PgfExn) as Pointer const err = ref.alloc(PgfExn) as Pointer
const txt = runtime.pgf_abstract_name(this.db, this.revision, err) const txt = runtime.pgf_abstract_name(this.db, this.revision, err)
handleError(err) handleError(err)
return PgfText_AsString(txt) return PgfText_AsString(txt)
} }
getCategories () { getCategories (): string[] {
const cats = new Array() const cats: string[] = []
const callback = ffi.Callback(ref.types.void, [ PgfItorPtr, PgfTextPtr, voidPtr, PgfExnPtr], const callback = ffi.Callback(ref.types.void, [ PgfItorPtr, PgfTextPtr, voidPtr, PgfExnPtr],
function (self: Pointer, key: Pointer, value: Pointer, err: Pointer) { function (self: Pointer, key: Pointer, value: Pointer, err: Pointer) { // eslint-disable-line @typescript-eslint/no-unused-vars
const k = PgfText_AsString(key) const k = PgfText_AsString(key)
cats.push(k) cats.push(k)
}) })
@@ -183,10 +183,10 @@ export class PGFGrammar {
return cats return cats
} }
getFunctions () { getFunctions (): string[] {
const funs = new Array() const funs: string[] = []
const callback = ffi.Callback(ref.types.void, [ PgfItorPtr, PgfTextPtr, voidPtr, PgfExnPtr], const callback = ffi.Callback(ref.types.void, [ PgfItorPtr, PgfTextPtr, voidPtr, PgfExnPtr],
function (self: Pointer, key: Pointer, value: Pointer, err: Pointer) { function (self: Pointer, key: Pointer, value: Pointer, err: Pointer) { // eslint-disable-line @typescript-eslint/no-unused-vars
const k = PgfText_AsString(key) const k = PgfText_AsString(key)
funs.push(k) funs.push(k)
}) })

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,7 @@
"description": "JavaScript bindings to the Grammatical Frameworks's PGF runtime", "description": "JavaScript bindings to the Grammatical Frameworks's PGF runtime",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"lint": "npx eslint . --ext .ts",
"build": "npx tsc", "build": "npx tsc",
"test": "npx jest" "test": "npx jest"
}, },
@@ -15,6 +16,9 @@
"devDependencies": { "devDependencies": {
"@types/ffi": "^0.2.3", "@types/ffi": "^0.2.3",
"@types/jest": "^27.0.2", "@types/jest": "^27.0.2",
"@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^4.32.0",
"eslint": "^7.32.0",
"jest": "^27.2.4", "jest": "^27.2.4",
"ts-jest": "^27.0.5", "ts-jest": "^27.0.5",
"typescript": "^4.4.3" "typescript": "^4.4.3"

View File

@@ -29,7 +29,9 @@ describe('bootNGF', () => {
beforeAll(() => { beforeAll(() => {
try { try {
fs.unlinkSync('./basic.ngf') fs.unlinkSync('./basic.ngf')
} catch { } } catch {
// empty
}
}) })
test('valid', () => { test('valid', () => {