Skip to content

Commit

Permalink
Add a couple additional lints to ensure consistent style (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 authored Aug 2, 2024
1 parent 0093f68 commit 3b4c45c
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"extends": "./node_modules/gts/",
"rules": {
"@typescript-eslint/explicit-function-return-type": [
"error",
{"allowExpressions": true}
],
"func-style": ["error", "declaration"],
"prefer-const": ["error", {"destructuring": "all"}],
// It would be nice to sort import declaration order as well, but that's not
// autofixable and it's not worth the effort of handling manually.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/compiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as compilerModule from './compiler/utils';
import {Compiler, initCompiler} from './compiler/sync';

const createDispatcher = jest.spyOn(compilerModule, 'createDispatcher');
function getIdHistory() {
function getIdHistory(): number[] {
return createDispatcher.mock.calls.map(([id]) => id);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Exception extends Error implements SassException {
this.span = deprotofySourceSpan(failure.span!);
}

toString() {
toString(): string {
return this.message;
}
}
4 changes: 2 additions & 2 deletions lib/src/legacy/value/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function wrapFunction<sync extends 'sync' | 'async'>(
} else {
return args =>
new Promise((resolve, reject) => {
const done = (result: unknown) => {
function done(result: unknown): void {
try {
if (result instanceof Error) {
reject(result);
Expand All @@ -52,7 +52,7 @@ export function wrapFunction<sync extends 'sync' | 'async'>(
} catch (error: unknown) {
reject(error);
}
};
}

// The cast here is necesary to work around microsoft/TypeScript#33815.
const syncResult = (callback as (...args: unknown[]) => unknown).apply(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet-transformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('packet transformer', () => {
describe('decode', () => {
let rawBuffers$: Subject<Buffer>;

function expectDecoding(expected: Buffer[], done: () => void) {
function expectDecoding(expected: Buffer[], done: () => void): void {
const actual: Buffer[] = [];
packets.outboundProtobufs$.subscribe({
next: protobuf => actual.push(protobuf),
Expand Down
6 changes: 3 additions & 3 deletions lib/src/request-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class RequestTracker {
> = [];

/** The next available request ID. */
get nextId() {
get nextId(): number {
for (let i = 0; i < this.requests.length; i++) {
if (this.requests[i] === undefined || this.requests[i] === null) {
return i;
Expand All @@ -32,7 +32,7 @@ export class RequestTracker {
add(
id: number,
expectedResponseType: InboundResponseType | OutboundResponseType
) {
): void {
if (id < 0) {
throw Error(`Invalid request ID ${id}.`);
} else if (this.requests[id]) {
Expand All @@ -47,7 +47,7 @@ export class RequestTracker {
* Resolves a pending request with matching ID `id` and expected response type
* `type`. Throws an error if the Protocol Error is violated.
*/
resolve(id: number, type: InboundResponseType | OutboundResponseType) {
resolve(id: number, type: InboundResponseType | OutboundResponseType): void {
if (this.requests[id] === undefined || this.requests[id] === null) {
throw Error(`Response ID ${id} does not match any pending requests.`);
} else if (this.requests[id] !== type) {
Expand Down
9 changes: 6 additions & 3 deletions lib/src/value/calculations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ function assertCalculationValue(value: CalculationValue): void {
}
}

const isValidClampArg = (value: CalculationValue): boolean =>
value instanceof CalculationInterpolation ||
(value instanceof SassString && !value.hasQuotes);
function isValidClampArg(value: CalculationValue): boolean {
return (
value instanceof CalculationInterpolation ||
(value instanceof SassString && !value.hasQuotes)
);
}

/* A SassScript calculation */
export class SassCalculation extends Value {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/value/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ function hwbToRgb(
hue: number,
scaledWhiteness: number,
scaledBlackness: number
) {
): number {
const factor = 1 - scaledWhiteness - scaledBlackness;
const channel = hueToRgb(0, 1, hue) * factor + scaledWhiteness;
return fuzzyRound(channel * 255);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/value/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function fuzzyAssertInRange(
}

/** Returns `dividend % modulus`, but always in the range `[0, modulus)`. */
export function positiveMod(dividend: number, modulus: number) {
export function positiveMod(dividend: number, modulus: number): number {
const result = dividend % modulus;
return result < 0 ? result + modulus : result;
}
2 changes: 1 addition & 1 deletion test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function expectEqualIgnoringWhitespace(
string1: string,
string2: string
): void {
function strip(str: string) {
function strip(str: string): string {
return str.replace(/\s+/g, '');
}
expect(strip(string1)).toBe(strip(string2));
Expand Down
2 changes: 1 addition & 1 deletion tool/get-deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function toVersionCode(version: string | undefined): string {
* Generates the list of deprecations based on the YAML file in the language
* repo.
*/
export async function getDeprecations(outDirectory: string) {
export async function getDeprecations(outDirectory: string): Promise<void> {
const yamlText = fs.readFileSync(yamlFile, 'utf8');

const deprecations = parse(yamlText) as YamlData;
Expand Down
2 changes: 1 addition & 1 deletion tool/prepare-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void (async () => {

// Quick sanity checks to make sure the release we are preparing is a suitable
// candidate for release.
async function sanityCheckBeforeRelease() {
async function sanityCheckBeforeRelease(): Promise<void> {
console.log('Running sanity checks before releasing.');
const releaseVersion = pkg.version;

Expand Down

0 comments on commit 3b4c45c

Please sign in to comment.