mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
Add linting
This commit is contained in:
2
src/runtime/javascript/.eslintignore
Normal file
2
src/runtime/javascript/.eslintignore
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
dist
|
||||
11
src/runtime/javascript/.eslintrc.js
Normal file
11
src/runtime/javascript/.eslintrc.js
Normal file
@@ -0,0 +1,11 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: [
|
||||
'@typescript-eslint',
|
||||
],
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
]
|
||||
}
|
||||
@@ -35,7 +35,7 @@ const PgfItor = Struct({
|
||||
const PgfItorPtr = ref.refType(PgfItor)
|
||||
|
||||
const PgfType = ref.types.void // TODO
|
||||
const PgfTypePtr = ref.refType(PgfType)
|
||||
// const PgfTypePtr = ref.refType(PgfType)
|
||||
|
||||
const PgfTypeHypo = ref.types.void // TODO
|
||||
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
|
||||
interface Pointer extends Buffer {
|
||||
deref(): any
|
||||
deref (): any // eslint-disable-line @typescript-eslint/no-explicit-any
|
||||
}
|
||||
|
||||
class PGFError extends Error {
|
||||
@@ -123,10 +123,10 @@ function handleError (errPtr: Pointer): void {
|
||||
case 0: return
|
||||
|
||||
// PGF_EXN_SYSTEM_ERROR
|
||||
case 1:
|
||||
case 1: {
|
||||
const desc = errno.lookup(err.code)
|
||||
throw new Error(`${desc}: ${err.msg}`)
|
||||
|
||||
}
|
||||
// PGF_EXN_PGF_ERROR
|
||||
case 2:
|
||||
throw new PGFError(err.msg)
|
||||
@@ -159,21 +159,21 @@ export class PGFGrammar {
|
||||
}
|
||||
|
||||
// NB the library user is responsible for calling this
|
||||
release () {
|
||||
release (): void {
|
||||
runtime.pgf_free_revision(this.db, this.revision)
|
||||
}
|
||||
|
||||
getAbstractName () {
|
||||
getAbstractName (): string {
|
||||
const err = ref.alloc(PgfExn) as Pointer
|
||||
const txt = runtime.pgf_abstract_name(this.db, this.revision, err)
|
||||
handleError(err)
|
||||
return PgfText_AsString(txt)
|
||||
}
|
||||
|
||||
getCategories () {
|
||||
const cats = new Array()
|
||||
getCategories (): string[] {
|
||||
const cats: string[] = []
|
||||
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)
|
||||
cats.push(k)
|
||||
})
|
||||
@@ -183,10 +183,10 @@ export class PGFGrammar {
|
||||
return cats
|
||||
}
|
||||
|
||||
getFunctions () {
|
||||
const funs = new Array()
|
||||
getFunctions (): string[] {
|
||||
const funs: string[] = []
|
||||
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)
|
||||
funs.push(k)
|
||||
})
|
||||
|
||||
876
src/runtime/javascript/package-lock.json
generated
876
src/runtime/javascript/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@
|
||||
"description": "JavaScript bindings to the Grammatical Frameworks's PGF runtime",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"lint": "npx eslint . --ext .ts",
|
||||
"build": "npx tsc",
|
||||
"test": "npx jest"
|
||||
},
|
||||
@@ -15,6 +16,9 @@
|
||||
"devDependencies": {
|
||||
"@types/ffi": "^0.2.3",
|
||||
"@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",
|
||||
"ts-jest": "^27.0.5",
|
||||
"typescript": "^4.4.3"
|
||||
|
||||
@@ -29,7 +29,9 @@ describe('bootNGF', () => {
|
||||
beforeAll(() => {
|
||||
try {
|
||||
fs.unlinkSync('./basic.ngf')
|
||||
} catch { }
|
||||
} catch {
|
||||
// empty
|
||||
}
|
||||
})
|
||||
|
||||
test('valid', () => {
|
||||
|
||||
Reference in New Issue
Block a user