Skip to content

Commit 09fe3f3

Browse files
[style] Use Prettier (#626)
* [style] Use Prettier and format src/ * [style] Apply Prettier to remaining files * [style] Preserve matrix formatting in cat-mat script * [style] Run Prettier without ESLint fix * [style] Use Stroustrup braces with Prettier * [style] Use prettier-plugin-space-before-function-paren * [style] Use prettier-plugin-merge * [style] Upgraade prettier-plugin-space-before-function-paren * [style] Run Prettier on missed files * [style] Manually add spacing to broken area * [style] Remove ESLint bracket spacing rule * [style] Remove ESLint stylistic
1 parent db3e23b commit 09fe3f3

File tree

129 files changed

+1896
-1893
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+1896
-1893
lines changed

.eslintrc.cjs

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
"browser": true,
1212
"es2020": true,
1313
},
14-
"plugins": ["@typescript-eslint", "@stylistic"],
14+
"plugins": ["@typescript-eslint"],
1515
"rules": {
1616
/**
1717
* ESLint rules: https://eslint.org/docs/latest/rules/
@@ -180,69 +180,6 @@ module.exports = {
180180
// https://eslint.org/docs/latest/rules/valid-typeof
181181
"valid-typeof": 1,
182182

183-
/**
184-
* ESLint Stylistic rules: https://eslint.style/packages/default#rules
185-
*/
186-
// Enforce a space before and after `=>` in arrow functions
187-
// https://eslint.style/rules/default/arrow-spacing
188-
"@stylistic/arrow-spacing": 1,
189-
// Enforce consistent brace style for blocks
190-
// https://eslint.style/rules/default/brace-style
191-
"@stylistic/brace-style": [1, "stroustrup"],
192-
// Enforce trailing commas unless closing `]` or `}` is on the same line
193-
// https://eslint.style/rules/default/comma-dangle
194-
"@stylistic/comma-dangle": [1, "always-multiline"],
195-
// Enforce no space before and one or more spaces after a comma
196-
// https://eslint.style/rules/default/comma-spacing
197-
"@stylistic/comma-spacing": 1,
198-
// Require newline at the end of files
199-
// https://eslint.style/rules/default/eol-last
200-
"@stylistic/eol-last": 1,
201-
// Enforce consistent indentation
202-
// https://eslint.style/rules/default/indent
203-
"@stylistic/indent": [1, "tab", { "SwitchCase": 1, "outerIIFEBody": 0 }],
204-
// Enforce consistent spacing before and after keywords
205-
// https://eslint.style/rules/default/keyword-spacing
206-
"@stylistic/keyword-spacing": 1,
207-
// Disallow unnecessary semicolons
208-
// https://eslint.style/rules/default/no-extra-semi
209-
"@stylistic/no-extra-semi": 1,
210-
// Disallow mixed spaces and tabs for indentation
211-
// https://eslint.style/rules/default/no-mixed-spaces-and-tabs
212-
"@stylistic/no-mixed-spaces-and-tabs": [1, "smart-tabs"],
213-
// Disallow trailing whitespace at the end of lines
214-
// https://eslint.style/rules/default/no-trailing-spaces
215-
"@stylistic/no-trailing-spaces": 1,
216-
// Enforce the consistent use of double quotes
217-
// https://eslint.style/rules/default/quotes
218-
"@stylistic/quotes": [
219-
1,
220-
"double",
221-
{ "avoidEscape": true, "allowTemplateLiterals": true },
222-
],
223-
// Require semicolons instead of ASI
224-
// https://eslint.style/rules/default/semi
225-
"@stylistic/semi": 1,
226-
// Enforce at least one space before blocks
227-
// https://eslint.style/rules/default/space-before-blocks
228-
"@stylistic/space-before-blocks": 1,
229-
// Enforce a space before `function` definition opening parenthesis
230-
// https://eslint.style/rules/default/space-before-function-paren
231-
"@stylistic/space-before-function-paren": 1,
232-
// Require spaces around infix operators (e.g. `+`, `=`, `?`, `:`)
233-
// https://eslint.style/rules/default/space-infix-ops
234-
"@stylistic/space-infix-ops": 1,
235-
// Enforce a space after unary word operators (`new`, `delete`, `typeof`, `void`, `yield`)
236-
// https://eslint.style/rules/default/space-unary-ops
237-
"@stylistic/space-unary-ops": 1,
238-
// Enforce whitespace after the `//` or `/*` in a comment
239-
// https://eslint.style/rules/default/spaced-comment
240-
"@stylistic/spaced-comment": [
241-
1,
242-
"always",
243-
{ "block": { "exceptions": ["*"] } },
244-
],
245-
246183
/**
247184
* typescript-eslint rules: https://typescript-eslint.io/rules/
248185
* Based off of: https://github.com/typescript-eslint/typescript-eslint/blob/v6.13.1/packages/eslint-plugin/src/configs/recommended.ts
@@ -252,13 +189,9 @@ module.exports = {
252189
"@typescript-eslint/ban-ts-comment": 1,
253190
// Disallow certain built-in types
254191
// https://typescript-eslint.io/rules/ban-types
255-
"@typescript-eslint/ban-types": [
256-
1,
257-
{
258-
extendDefaults: true,
259-
types: { "{}": false },
260-
},
261-
],
192+
"@typescript-eslint/no-empty-object-type": 0,
193+
"@typescript-eslint/no-unsafe-function-type": 1,
194+
"@typescript-eslint/no-wrapper-object-types": 1,
262195
// Disallow generic `Array` constructors
263196
// https://typescript-eslint.io/rules/no-array-constructor
264197
"@typescript-eslint/no-array-constructor": 1,

.prettierignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
!.*
2+
assets/js/prism.js
3+
api/
4+
/dist/
5+
docs/
6+
types/src/
7+
node_modules/
8+
9+
# Contains custom spacing around re-exports
10+
src/index-fn.js
11+
# Contains JS object with explicit quotes around keys, eg. { "constructor-super": 1 }
12+
.eslintrc.cjs

.prettierrc.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"plugins": [
3+
"prettier-plugin-brace-style",
4+
"prettier-plugin-space-before-function-paren",
5+
"prettier-plugin-merge"
6+
],
7+
"braceStyle": "stroustrup",
8+
"arrowParens": "avoid",
9+
"bracketSpacing": true,
10+
"endOfLine": "auto",
11+
"semi": true,
12+
"singleQuote": false,
13+
"tabWidth": 4,
14+
"useTabs": true,
15+
"trailingComma": "all",
16+
"printWidth": 100
17+
}

_build/eleventy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import * as filters from "./filters.js";
55

66
export default config => {
77
let data = {
8-
"layout": "page.njk",
9-
"permalink": "{{ page.filePathStem }}.html",
8+
layout: "page.njk",
9+
permalink: "{{ page.filePathStem }}.html",
1010
};
1111

1212
for (let p in data) {

_build/filters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ export function randomNumber (max, min, step) {
2020
// Round to nearest power of 10
2121
step = Math.pow(10, Math.floor(Math.log10(step)));
2222

23-
return Math.floor(Math.random() * (max - min + step) / step) * step + min;
23+
return Math.floor((Math.random() * (max - min + step)) / step) * step + min;
2424
}

_build/rollup.config.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,40 @@ import terser from "@rollup/plugin-terser";
22

33
const bundles = [
44
{
5-
"file": "dist/color.global.js",
6-
"format": "iife",
7-
"sourcemap": true,
8-
"name": "Color",
5+
file: "dist/color.global.js",
6+
format: "iife",
7+
sourcemap: true,
8+
name: "Color",
99
},
1010
{
11-
"file": "dist/color.js",
12-
"format": "esm",
13-
"sourcemap": true,
11+
file: "dist/color.js",
12+
format: "esm",
13+
sourcemap: true,
1414
},
1515
{
16-
"file": "dist/color.cjs",
17-
"format": "cjs",
18-
"sourcemap": true,
19-
"exports": "named",
16+
file: "dist/color.cjs",
17+
format: "cjs",
18+
sourcemap: true,
19+
exports: "named",
2020
},
2121
];
2222

2323
const fnBundles = [
2424
{
25-
"file": "dist/color-fn.cjs",
26-
"format": "cjs",
27-
"sourcemap": true,
28-
"exports": "named",
25+
file: "dist/color-fn.cjs",
26+
format: "cjs",
27+
sourcemap: true,
28+
exports: "named",
2929
},
3030
{
31-
"file": "dist/color-fn.js",
32-
"format": "esm",
33-
"sourcemap": true,
31+
file: "dist/color-fn.js",
32+
format: "esm",
33+
sourcemap: true,
3434
},
3535
];
3636

3737
// Add minified versions of every bundle
38-
const addMinBundle = (bundles) => {
38+
const addMinBundle = bundles => {
3939
return bundles.flatMap(bundle => {
4040
const minBundle = Object.assign({}, bundle);
4141
minBundle.file = minBundle.file.replace(/\.\w+$/, ".min$&");

_build/rollup.legacy.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ export default defaultConfig.map(config =>
1717
file: bundle.file.replace(/\.(?:min\.)?\w+$/, ".legacy$&"),
1818
})),
1919
plugins: [...(config.plugins || []), ...legacyPlugins],
20-
}),
21-
);
20+
}));

assets/js/colors.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let colors = {
88
blue: new Color(root_cs.getPropertyValue("--color-blue")),
99
};
1010
let supportsP3 = window.CSS && CSS.supports("color", "color(display-p3 0 1 0)");
11-
let interpolationOptions = {steps: 5, space: "lch", outputSpace: supportsP3 ? "p3" : "hsl"};
11+
let interpolationOptions = { steps: 5, space: "lch", outputSpace: supportsP3 ? "p3" : "hsl" };
1212

1313
if (!Color.DEBUGGING) {
1414
let redGreen = colors.red.range(colors.green, interpolationOptions);
@@ -21,29 +21,33 @@ if (!Color.DEBUGGING) {
2121
...Color.steps(greenBlue, interpolationOptions),
2222
...Color.steps(blueRed, interpolationOptions),
2323
],
24-
"color-red-light": colors.red.clone().set({"lch.l": 80}),
25-
"color-green-light": colors.green.clone().set({"lch.l": 80}),
26-
"color-blue-light": colors.blue.clone().set({"lch.l": 80}),
24+
"color-red-light": colors.red.clone().set({ "lch.l": 80 }),
25+
"color-green-light": colors.green.clone().set({ "lch.l": 80 }),
26+
"color-blue-light": colors.blue.clone().set({ "lch.l": 80 }),
2727

28-
"color-red-lighter": colors.red.clone().set({"lch.l": 94}),
29-
"color-green-lighter": colors.green.clone().set({"lch.l": 95}),
30-
"color-blue-lighter": colors.blue.clone().set({"lch.l": 94}),
28+
"color-red-lighter": colors.red.clone().set({ "lch.l": 94 }),
29+
"color-green-lighter": colors.green.clone().set({ "lch.l": 95 }),
30+
"color-blue-lighter": colors.blue.clone().set({ "lch.l": 94 }),
3131

32-
"color-red-green": redGreen(.5),
33-
"color-green-blue": greenBlue(.5),
34-
"color-blue-red": blueRed(.5),
32+
"color-red-green": redGreen(0.5),
33+
"color-green-blue": greenBlue(0.5),
34+
"color-blue-red": blueRed(0.5),
3535

36-
"color-red-green-light": redGreen(.5).set({"lch.l": 94}),
37-
"color-green-blue-light": greenBlue(.5).set({"lch.l": 94}),
38-
"color-blue-red-light": blueRed(.5).set({"lch.l": 94}),
36+
"color-red-green-light": redGreen(0.5).set({ "lch.l": 94 }),
37+
"color-green-blue-light": greenBlue(0.5).set({ "lch.l": 94 }),
38+
"color-blue-red-light": blueRed(0.5).set({ "lch.l": 94 }),
3939
};
4040

4141
window.vars = vars;
4242

43-
document.head.insertAdjacentHTML("beforeend",
43+
document.head.insertAdjacentHTML(
44+
"beforeend",
4445
`<style>
4546
:root {
46-
${Object.entries(vars).map(pair => `--${pair[0]}: ${pair[1]}`).join(";")};
47+
${Object.entries(vars)
48+
.map(pair => `--${pair[0]}: ${pair[1]}`)
49+
.join(";")};
4750
}
48-
</style>`);
51+
</style>`,
52+
);
4953
}

assets/js/docs.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ if (current) {
4343
function idify (str) {
4444
// from Mavo.Functions.idify()
4545
return str
46-
.normalize("NFD").replace(/[\u0300-\u036f]/g, "") // Convert accented letters to ASCII
46+
.normalize("NFD")
47+
.replace(/[\u0300-\u036f]/g, "") // Convert accented letters to ASCII
4748
.replace(/[^\w\s-]/g, "") // Remove remaining non-ASCII characters
48-
.trim().replace(/\s+/g, "-") // Convert whitespace to hyphens
49+
.trim()
50+
.replace(/\s+/g, "-") // Convert whitespace to hyphens
4951
.toLowerCase();
5052
}
5153

assets/js/enhance.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ export function styleCallouts (
66
labels = new RegExp(`(${labels.join("|")}):`);
77

88
for (let p of elements) {
9-
let callout = p.textContent.trimLeft().slice(0, maxLabelLength + 2).match(labels)?.[1];
9+
let callout = p.textContent
10+
.trimLeft()
11+
.slice(0, maxLabelLength + 2)
12+
.match(labels)?.[1];
1013

1114
if (callout) {
1215
p.classList.add(callout.toLowerCase());

assets/js/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ if (location.pathname.indexOf("/docs/") > -1 && window.toc) {
1010
}
1111

1212
styleCallouts();
13-

color.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ window.Color = window.Color || Color;
77

88
// Re-export
99
export default Color;
10-
export {util};
10+
export { util };

data/spaces.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import ColorSpace from "../src/spaces/index.js";
2-
import {WHITES} from "../src/adapt.js";
2+
import { WHITES } from "../src/adapt.js";
33

44
let whitePoints = Object.entries(WHITES);
55

@@ -24,12 +24,12 @@ modules.space = Object.fromEntries(modules.space.map(meta => [meta.id, meta]));
2424

2525
for (let id in ColorSpace.registry) {
2626
let space = ColorSpace.registry[id];
27-
let meta = spaces[id] = Object.assign(modules.space[id] ?? {}, {
27+
let meta = (spaces[id] = Object.assign(modules.space[id] ?? {}, {
2828
name: space.name,
2929
white: whitePoints.find(([name, white]) => white === space.white)?.[0] ?? "D65",
3030
base: space.base,
3131
coords: space.coords,
32-
});
32+
}));
3333

3434
if (space.id != id) {
3535
meta.aliasOf = ColorSpace.registry[space.id].name;

get/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ $("a[download]")?.addEventListener("click", evt => {
1313
});
1414

1515
function createURL (code, type = "text/javascript") {
16-
var blob = new Blob([code], {type});
16+
var blob = new Blob([code], { type });
1717

1818
return URL.createObjectURL(blob);
1919
}

0 commit comments

Comments
 (0)