Skip to content

Commit 762ff20

Browse files
authored
Use prettier for formatting. (#95)
1 parent ab6ae82 commit 762ff20

22 files changed

+457
-545
lines changed

.eslintrc.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ module.exports = {
1111
'extends': [
1212
'eslint:recommended',
1313
'plugin:@typescript-eslint/eslint-recommended',
14-
'plugin:@typescript-eslint/recommended'
14+
'plugin:@typescript-eslint/recommended',
15+
'prettier',
16+
'prettier/@typescript-eslint'
1517
],
1618
'parser': '@typescript-eslint/parser',
1719
'parserOptions': {
@@ -68,10 +70,6 @@ module.exports = {
6870
'error',
6971
'never'
7072
],
71-
'implicit-arrow-linebreak': [
72-
'error',
73-
'beside'
74-
],
7573
'@typescript-eslint/indent': [
7674
'error',
7775
2,
@@ -98,13 +96,7 @@ module.exports = {
9896
'mode': 'strict'
9997
}
10098
],
101-
'@typescript-eslint/keyword-spacing': [
102-
'error',
103-
{
104-
'after': true,
105-
'before': true
106-
}
107-
],
99+
'@typescript-eslint/keyword-spacing': 'off',
108100
'linebreak-style': [
109101
'error',
110102
'unix'
@@ -121,7 +113,7 @@ module.exports = {
121113
'error',
122114
{
123115
'singleline': {
124-
'delimiter': 'comma',
116+
'delimiter': 'semi',
125117
'requireLast': false
126118
},
127119
'multiline': {
@@ -194,7 +186,7 @@ module.exports = {
194186
],
195187
'object-curly-spacing': [
196188
'error',
197-
'never'
189+
'always'
198190
],
199191
'object-property-newline': [
200192
'error',
@@ -204,7 +196,13 @@ module.exports = {
204196
],
205197
'operator-linebreak': [
206198
'error',
207-
'after'
199+
'after',
200+
{
201+
'overrides': {
202+
'?': 'before',
203+
':': 'before'
204+
}
205+
}
208206
],
209207
'padded-blocks': [
210208
'error',
@@ -248,7 +246,7 @@ module.exports = {
248246
'@typescript-eslint/space-before-function-paren': [
249247
'error',
250248
{
251-
'anonymous': 'never',
249+
'anonymous': 'always',
252250
'asyncArrow': 'always',
253251
'named': 'never'
254252
}

.github/workflows/build.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
node_version: [
16+
node-version: [
1717
10,
1818
12,
1919
14,
@@ -22,10 +22,13 @@ jobs:
2222
- uses: actions/checkout@v2
2323
- uses: actions/setup-node@v1
2424
with:
25-
node-version: ${{ matrix.node_version }}
25+
node-version: ${{ matrix.node-version }}
2626
- name: Install dependencies
2727
run: |
2828
npm ci
29+
- name: Check formatting
30+
run: |
31+
npx prettier -c '*.js' 'src/*.ts'
2932
- name: Lint with eslint
3033
run: |
3134
npm run lint

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.eslintrc.js

.prettierrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"printWidth": 100,
3+
"singleQuote": true
4+
}

generate-types.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
// eslint-disable-next-line @typescript-eslint/no-var-requires
21
const fs = require('fs');
3-
// eslint-disable-next-line @typescript-eslint/no-var-requires
4-
const {compileFromFile} = require('json-schema-to-typescript');
5-
6-
// eslint-disable-next-line @typescript-eslint/no-var-requires
2+
const { compileFromFile } = require('json-schema-to-typescript');
73
const path = require('path');
84

9-
compileFromFile('schema/schema.json', {cwd: 'schema'})
10-
.then((ts) => fs.writeFileSync('src/schema.ts', ts));
5+
compileFromFile('schema/schema.json', { cwd: 'schema' }).then((ts) =>
6+
fs.writeFileSync('src/schema.ts', ts)
7+
);
118

129
const dname = path.resolve(path.join(__dirname, 'schema', 'messages'));
1310

@@ -17,8 +14,7 @@ for (const fname of fs.readdirSync(dname)) {
1714
const schemaPath = path.join(dname, fname);
1815
const schema = JSON.parse(fs.readFileSync(schemaPath).toString());
1916

20-
if (!schema.hasOwnProperty('properties') ||
21-
!schema.properties.hasOwnProperty('messageType')) {
17+
if (!schema.hasOwnProperty('properties') || !schema.properties.hasOwnProperty('messageType')) {
2218
continue;
2319
}
2420

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "Bindings for WebThings Gateway add-ons",
55
"scripts": {
66
"build": "if [ ! -d schema/messages ]; then git submodule init; fi; git submodule update && node generate-types.js && tsc -p .",
7-
"lint": "eslint src --ext .ts"
7+
"lint": "eslint src --ext .ts",
8+
"prettier": "npx prettier -w '*.js' 'src/*.ts'"
89
},
910
"main": "lib/index.js",
1011
"keywords": [
@@ -33,7 +34,9 @@
3334
"@typescript-eslint/parser": "^4.14.1",
3435
"babel-eslint": "^10.1.0",
3536
"eslint": "^7.18.0",
37+
"eslint-config-prettier": "^7.2.0",
3638
"json-schema-to-typescript": "^10.1.3",
39+
"prettier": "^2.2.1",
3740
"typescript": "^4.1.3"
3841
},
3942
"files": [

src/action.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
*/
88

9-
import {Device} from './device';
10-
import {ActionDescription, Any} from './schema';
11-
import {timestamp} from './utils';
9+
import { Device } from './device';
10+
import { ActionDescription, Any } from './schema';
11+
import { timestamp } from './utils';
1212

1313
/**
1414
* An Action represents an individual action on a device.
@@ -29,13 +29,13 @@ export class Action {
2929
private input?: Any;
3030

3131
/**
32-
* Initialize the object.
33-
*
34-
* @param {String} id ID of this action
35-
* @param {Object} device Device this action belongs to
36-
* @param {String} name Name of the action
37-
* @param {unknown} input Any action inputs
38-
*/
32+
* Initialize the object.
33+
*
34+
* @param {String} id ID of this action
35+
* @param {Object} device Device this action belongs to
36+
* @param {String} name Name of the action
37+
* @param {unknown} input Any action inputs
38+
*/
3939
constructor(id: string, device: Device, name: string, input?: Any) {
4040
this.id = id;
4141
this.device = device;

src/adapter.ts

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@
99
* file, You can obtain one at http://mozilla.org/MPL/2.0/.*
1010
*/
1111

12-
import {Action} from './action';
13-
import {AddonManagerProxy} from './addon-manager-proxy';
14-
import {Device} from './device';
15-
import {DeviceWithoutId as DeviceWithoutIdSchema,
16-
Preferences,
17-
UserProfile} from './schema';
18-
12+
import { Action } from './action';
13+
import { AddonManagerProxy } from './addon-manager-proxy';
14+
import { Device } from './device';
15+
import { DeviceWithoutId as DeviceWithoutIdSchema, Preferences, UserProfile } from './schema';
1916

2017
export interface AdapterDescription {
2118
id: string;
@@ -51,8 +48,12 @@ export class Adapter {
5148

5249
private preferences?: Preferences;
5350

54-
constructor(manager: AddonManagerProxy, id: string, packageName: string,
55-
{verbose}: Record<string, unknown> = {}) {
51+
constructor(
52+
manager: AddonManagerProxy,
53+
id: string,
54+
packageName: string,
55+
{ verbose }: Record<string, unknown> = {}
56+
) {
5657
this.manager = manager;
5758
this.id = id;
5859
this.packageName = packageName;
@@ -176,12 +177,10 @@ export class Adapter {
176177
* @param {string} deviceId - ID of the device
177178
* @param {object} device - the saved device description
178179
*/
179-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
180180
handleDeviceSaved(_deviceId: string, _device: DeviceWithoutIdSchema): void {
181-
// eslint-disable-next-line @typescript-eslint/no-empty-function
181+
// pass
182182
}
183183

184-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
185184
startPairing(_timeoutSeconds: number): void {
186185
if (this.verbose) {
187186
console.log('Adapter:', this.name, 'id', this.id, 'pairing started');
@@ -220,17 +219,23 @@ export class Adapter {
220219

221220
removeThing(device: Device): void {
222221
if (this.verbose) {
223-
console.log('Adapter:', this.name, 'id', this.id,
224-
'removeThing(', device.getId(), ') started');
222+
console.log(
223+
'Adapter:',
224+
this.name,
225+
'id',
226+
this.id,
227+
'removeThing(',
228+
device.getId(),
229+
') started'
230+
);
225231
}
226232

227233
this.handleDeviceRemoved(device);
228234
}
229235

230236
cancelRemoveThing(device: Device): void {
231237
if (this.verbose) {
232-
console.log('Adapter:', this.name, 'id', this.id,
233-
'cancelRemoveThing(', device.getId(), ')');
238+
console.log('Adapter:', this.name, 'id', this.id, 'cancelRemoveThing(', device.getId(), ')');
234239
}
235240
}
236241

@@ -259,8 +264,7 @@ export class Adapter {
259264
const device = this.getDevice(deviceId);
260265
if (device) {
261266
if (this.verbose) {
262-
console.log('Adapter:', this.name, 'id', this.id,
263-
'setPin(', deviceId, ',', pin, ')');
267+
console.log('Adapter:', this.name, 'id', this.id, 'setPin(', deviceId, ',', pin, ')');
264268
}
265269

266270
return Promise.resolve();
@@ -282,9 +286,19 @@ export class Adapter {
282286
const device = this.getDevice(deviceId);
283287
if (device) {
284288
if (this.verbose) {
285-
console.log('Adapter:', this.name, 'id', this.id,
286-
'setCredentials(', deviceId, ',', username, ',', password,
287-
')');
289+
console.log(
290+
'Adapter:',
291+
this.name,
292+
'id',
293+
this.id,
294+
'setCredentials(',
295+
deviceId,
296+
',',
297+
username,
298+
',',
299+
password,
300+
')'
301+
);
288302
}
289303

290304
return Promise.resolve();

0 commit comments

Comments
 (0)