mirror of
https://github.com/chirimen-oh/node-web-gpio.git
synced 2025-01-18 16:08:00 +00:00
Feature/lint (#22)
* eslint package install * scrupt add . * warning resolved * warning resolced * error Async function 'requestGPIOAccess' has no 'await' expression resolved * Promise returned in function argument where a void return was expected resolved * package-lock.json 削除 * script improve * temporary commit * L234 disabled eslint rules * L159 lint disabled * レビュー指摘事項反映
This commit is contained in:
parent
80411187ea
commit
13b6bc57b1
4 changed files with 50 additions and 8 deletions
24
.eslintrc.js
Normal file
24
.eslintrc.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
module.exports = {
|
||||
root: true,
|
||||
env: {
|
||||
es6: true,
|
||||
node: true,
|
||||
},
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
ecmaVersion: 2019, // Node.js 12の場合は2019、他のバージョンのNode.jsを利用している場合は場合は適宜変更する
|
||||
tsconfigRootDir: __dirname,
|
||||
project: ['./tsconfig.eslint.json']
|
||||
},
|
||||
plugins: [
|
||||
'@typescript-eslint',
|
||||
],
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:@typescript-eslint/recommended-requiring-type-checking',
|
||||
],
|
||||
rules: {
|
||||
},
|
||||
};
|
17
index.ts
17
index.ts
|
@ -62,7 +62,7 @@ export class GPIOAccess extends EventEmitter {
|
|||
/**
|
||||
* Unexport all exported GPIO ports.
|
||||
*/
|
||||
async unexportAll() {
|
||||
async unexportAll(): Promise<void> {
|
||||
await Promise.all(
|
||||
[...this.ports.values()].map(port =>
|
||||
port.exported ? port.unexport() : undefined
|
||||
|
@ -121,7 +121,7 @@ export class GPIOPort extends EventEmitter {
|
|||
return this._exported;
|
||||
}
|
||||
|
||||
async export(direction: DirectionMode) {
|
||||
async export(direction: DirectionMode): Promise<void> {
|
||||
if (!/^(in|out)$/.test(direction)) {
|
||||
throw new InvalidAccessError(`Must be "in" or "out".`);
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ export class GPIOPort extends EventEmitter {
|
|||
}
|
||||
|
||||
try {
|
||||
clearInterval(this._timeout as any);
|
||||
clearInterval(this._timeout as ReturnType<typeof setInterval>);
|
||||
if (!this.exported) {
|
||||
await fs.writeFile(
|
||||
path.join(SysfsGPIOPath, "export"),
|
||||
|
@ -147,6 +147,7 @@ export class GPIOPort extends EventEmitter {
|
|||
);
|
||||
if (direction === "in") {
|
||||
this._timeout = setInterval(
|
||||
// eslint-disable-next-line
|
||||
this.read.bind(this),
|
||||
this._pollingInterval
|
||||
);
|
||||
|
@ -159,8 +160,8 @@ export class GPIOPort extends EventEmitter {
|
|||
this._exported = true;
|
||||
}
|
||||
|
||||
async unexport() {
|
||||
clearInterval(this._timeout as any);
|
||||
async unexport(): Promise<void> {
|
||||
clearInterval(this._timeout as ReturnType<typeof setInterval>);
|
||||
|
||||
try {
|
||||
await fs.writeFile(
|
||||
|
@ -174,7 +175,7 @@ export class GPIOPort extends EventEmitter {
|
|||
this._exported = false;
|
||||
}
|
||||
|
||||
async read() {
|
||||
async read(): Promise<GPIOValue> {
|
||||
if (!(this.exported && this.direction === "in")) {
|
||||
throw new InvalidAccessError(
|
||||
`The exported must be true and value of direction must be "in".`
|
||||
|
@ -199,7 +200,7 @@ export class GPIOPort extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
async write(value: GPIOValue) {
|
||||
async write(value: GPIOValue): Promise<void> {
|
||||
if (!(this.exported && this.direction === "out")) {
|
||||
throw new InvalidAccessError(
|
||||
`The exported must be true and value of direction must be "out".`
|
||||
|
@ -231,6 +232,8 @@ export class OperationError extends Error {
|
|||
}
|
||||
}
|
||||
|
||||
// Web GPIOの仕様に基づく意図的なasync関数の使用なので、ルールを無効化
|
||||
// eslint-disable-next-line
|
||||
export async function requestGPIOAccess(): Promise<GPIOAccess> {
|
||||
const ports = new GPIOPortMap(
|
||||
[...Array(GPIOPortMapSizeMax).keys()].map(portNumber => [
|
||||
|
|
|
@ -15,10 +15,14 @@
|
|||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "^14.14.25",
|
||||
"typescript": "^4.1.3"
|
||||
"@typescript-eslint/eslint-plugin": "^4.15.0",
|
||||
"@typescript-eslint/parser": "^4.15.0",
|
||||
"eslint": "^7.20.0",
|
||||
"typescript": "^4.1.5"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"lint": "eslint index.ts",
|
||||
"prepare": "rm -rf dist && npm run build"
|
||||
},
|
||||
"keywords": [
|
||||
|
|
11
tsconfig.eslint.json
Normal file
11
tsconfig.eslint.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": [
|
||||
"*.ts",
|
||||
".eslintrc.js"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"dist"
|
||||
]
|
||||
}
|
Loading…
Add table
Reference in a new issue