1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00
unleash.unleash/src/lib/services/state-util.ts
Christopher Kolstad 6673d131fe
feat: biome lint (#4853)
This commit changes our linter/formatter to biome (https://biomejs.dev/)
Causing our prehook to run almost instantly, and our "yarn lint" task to
run in sub 100ms.

Some trade-offs:
* Biome isn't quite as well established as ESLint
* Are we ready to install a different vscode plugin (the biome plugin)
instead of the prettier plugin


The configuration set for biome also has a set of recommended rules,
this is turned on by default, in order to get to something that was
mergeable I have turned off a couple the rules we seemed to violate the
most, that we also explicitly told eslint to ignore.
2023-09-29 14:18:21 +02:00

36 lines
1.1 KiB
TypeScript

import * as fs from 'fs';
import * as mime from 'mime';
import * as YAML from 'js-yaml';
export const readFile: (file: string) => Promise<string> = (file) =>
new Promise((resolve, reject) =>
fs.readFile(file, (err, v) =>
err ? reject(err) : resolve(v.toString('utf-8')),
),
);
export const parseFile: (file: string, data: string) => any = (
file: string,
data: string,
) => (mime.getType(file) === 'text/yaml' ? YAML.load(data) : JSON.parse(data));
export const filterExisting: (
keepExisting: boolean,
existingArray: any[],
) => (item: any) => boolean = (keepExisting, existingArray = []) => (item) => {
if (keepExisting) {
const found = existingArray.find((t) => t.name === item.name);
return !found;
}
return true;
};
export const filterEqual: (existingArray: any[]) => (item: any) => boolean =
(existingArray = []) => (item) => {
const toggle = existingArray.find((t) => t.name === item.name);
if (toggle) {
return JSON.stringify(toggle) !== JSON.stringify(item);
}
return true;
};