Skip to content

Commit 3b4c45c

Browse files
authored
Add a couple additional lints to ensure consistent style (#321)
1 parent 0093f68 commit 3b4c45c

File tree

12 files changed

+24
-16
lines changed

12 files changed

+24
-16
lines changed

.eslintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
22
"extends": "./node_modules/gts/",
33
"rules": {
4+
"@typescript-eslint/explicit-function-return-type": [
5+
"error",
6+
{"allowExpressions": true}
7+
],
8+
"func-style": ["error", "declaration"],
49
"prefer-const": ["error", {"destructuring": "all"}],
510
// It would be nice to sort import declaration order as well, but that's not
611
// autofixable and it's not worth the effort of handling manually.

lib/src/compiler.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as compilerModule from './compiler/utils';
99
import {Compiler, initCompiler} from './compiler/sync';
1010

1111
const createDispatcher = jest.spyOn(compilerModule, 'createDispatcher');
12-
function getIdHistory() {
12+
function getIdHistory(): number[] {
1313
return createDispatcher.mock.calls.map(([id]) => id);
1414
}
1515

lib/src/exception.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class Exception extends Error implements SassException {
1919
this.span = deprotofySourceSpan(failure.span!);
2020
}
2121

22-
toString() {
22+
toString(): string {
2323
return this.message;
2424
}
2525
}

lib/src/legacy/value/wrap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function wrapFunction<sync extends 'sync' | 'async'>(
4242
} else {
4343
return args =>
4444
new Promise((resolve, reject) => {
45-
const done = (result: unknown) => {
45+
function done(result: unknown): void {
4646
try {
4747
if (result instanceof Error) {
4848
reject(result);
@@ -52,7 +52,7 @@ export function wrapFunction<sync extends 'sync' | 'async'>(
5252
} catch (error: unknown) {
5353
reject(error);
5454
}
55-
};
55+
}
5656

5757
// The cast here is necesary to work around microsoft/TypeScript#33815.
5858
const syncResult = (callback as (...args: unknown[]) => unknown).apply(

lib/src/packet-transformer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('packet transformer', () => {
5555
describe('decode', () => {
5656
let rawBuffers$: Subject<Buffer>;
5757

58-
function expectDecoding(expected: Buffer[], done: () => void) {
58+
function expectDecoding(expected: Buffer[], done: () => void): void {
5959
const actual: Buffer[] = [];
6060
packets.outboundProtobufs$.subscribe({
6161
next: protobuf => actual.push(protobuf),

lib/src/request-tracker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class RequestTracker {
1616
> = [];
1717

1818
/** The next available request ID. */
19-
get nextId() {
19+
get nextId(): number {
2020
for (let i = 0; i < this.requests.length; i++) {
2121
if (this.requests[i] === undefined || this.requests[i] === null) {
2222
return i;
@@ -32,7 +32,7 @@ export class RequestTracker {
3232
add(
3333
id: number,
3434
expectedResponseType: InboundResponseType | OutboundResponseType
35-
) {
35+
): void {
3636
if (id < 0) {
3737
throw Error(`Invalid request ID ${id}.`);
3838
} else if (this.requests[id]) {
@@ -47,7 +47,7 @@ export class RequestTracker {
4747
* Resolves a pending request with matching ID `id` and expected response type
4848
* `type`. Throws an error if the Protocol Error is violated.
4949
*/
50-
resolve(id: number, type: InboundResponseType | OutboundResponseType) {
50+
resolve(id: number, type: InboundResponseType | OutboundResponseType): void {
5151
if (this.requests[id] === undefined || this.requests[id] === null) {
5252
throw Error(`Response ID ${id} does not match any pending requests.`);
5353
} else if (this.requests[id] !== type) {

lib/src/value/calculations.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ function assertCalculationValue(value: CalculationValue): void {
2323
}
2424
}
2525

26-
const isValidClampArg = (value: CalculationValue): boolean =>
27-
value instanceof CalculationInterpolation ||
28-
(value instanceof SassString && !value.hasQuotes);
26+
function isValidClampArg(value: CalculationValue): boolean {
27+
return (
28+
value instanceof CalculationInterpolation ||
29+
(value instanceof SassString && !value.hasQuotes)
30+
);
31+
}
2932

3033
/* A SassScript calculation */
3134
export class SassCalculation extends Value {

lib/src/value/color.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ function hwbToRgb(
350350
hue: number,
351351
scaledWhiteness: number,
352352
scaledBlackness: number
353-
) {
353+
): number {
354354
const factor = 1 - scaledWhiteness - scaledBlackness;
355355
const channel = hueToRgb(0, 1, hue) * factor + scaledWhiteness;
356356
return fuzzyRound(channel * 255);

lib/src/value/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function fuzzyAssertInRange(
116116
}
117117

118118
/** Returns `dividend % modulus`, but always in the range `[0, modulus)`. */
119-
export function positiveMod(dividend: number, modulus: number) {
119+
export function positiveMod(dividend: number, modulus: number): number {
120120
const result = dividend % modulus;
121121
return result < 0 ? result + modulus : result;
122122
}

test/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function expectEqualIgnoringWhitespace(
4848
string1: string,
4949
string2: string
5050
): void {
51-
function strip(str: string) {
51+
function strip(str: string): string {
5252
return str.replace(/\s+/g, '');
5353
}
5454
expect(strip(string1)).toBe(strip(string2));

0 commit comments

Comments
 (0)