Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[style] Use Prettier #626

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,6 @@ module.exports = {
// Enforce at least one space before blocks
// https://eslint.style/rules/default/space-before-blocks
"@stylistic/space-before-blocks": 1,
// Enforce a space before `function` definition opening parenthesis
// https://eslint.style/rules/default/space-before-function-paren
"@stylistic/space-before-function-paren": 1,
// Require spaces around infix operators (e.g. `+`, `=`, `?`, `:`)
// https://eslint.style/rules/default/space-infix-ops
"@stylistic/space-infix-ops": 1,
Expand All @@ -252,13 +249,9 @@ module.exports = {
"@typescript-eslint/ban-ts-comment": 1,
// Disallow certain built-in types
// https://typescript-eslint.io/rules/ban-types
"@typescript-eslint/ban-types": [
1,
{
extendDefaults: true,
types: { "{}": false },
},
],
"@typescript-eslint/no-empty-object-type": 0,
"@typescript-eslint/no-unsafe-function-type": 1,
"@typescript-eslint/no-wrapper-object-types": 1,
// Disallow generic `Array` constructors
// https://typescript-eslint.io/rules/no-array-constructor
"@typescript-eslint/no-array-constructor": 1,
Expand Down
12 changes: 12 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
!.*
assets/js/prism.js
api/
/dist/
docs/
types/src/
node_modules/

# Contains custom spacing around re-exports
src/index-fn.js
# Contains JS object with explicit quotes around keys, eg. { "constructor-super": 1 }
.eslintrc.cjs
17 changes: 17 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"plugins": [
"prettier-plugin-brace-style",
"prettier-plugin-space-before-function-paren",
"prettier-plugin-merge"
],
"braceStyle": "stroustrup",
"arrowParens": "avoid",
"bracketSpacing": true,
"endOfLine": "auto",
"semi": true,
"singleQuote": false,
"tabWidth": 4,
"useTabs": true,
"trailingComma": "all",
"printWidth": 100
}
4 changes: 2 additions & 2 deletions _build/eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import * as filters from "./filters.js";

export default config => {
let data = {
"layout": "page.njk",
"permalink": "{{ page.filePathStem }}.html",
layout: "page.njk",
permalink: "{{ page.filePathStem }}.html",
};

for (let p in data) {
Expand Down
2 changes: 1 addition & 1 deletion _build/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export function randomNumber (max, min, step) {
// Round to nearest power of 10
step = Math.pow(10, Math.floor(Math.log10(step)));

return Math.floor(Math.random() * (max - min + step) / step) * step + min;
return Math.floor((Math.random() * (max - min + step)) / step) * step + min;
}
38 changes: 19 additions & 19 deletions _build/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@ import terser from "@rollup/plugin-terser";

const bundles = [
{
"file": "dist/color.global.js",
"format": "iife",
"sourcemap": true,
"name": "Color",
file: "dist/color.global.js",
format: "iife",
sourcemap: true,
name: "Color",
},
{
"file": "dist/color.js",
"format": "esm",
"sourcemap": true,
file: "dist/color.js",
format: "esm",
sourcemap: true,
},
{
"file": "dist/color.cjs",
"format": "cjs",
"sourcemap": true,
"exports": "named",
file: "dist/color.cjs",
format: "cjs",
sourcemap: true,
exports: "named",
},
];

const fnBundles = [
{
"file": "dist/color-fn.cjs",
"format": "cjs",
"sourcemap": true,
"exports": "named",
file: "dist/color-fn.cjs",
format: "cjs",
sourcemap: true,
exports: "named",
},
{
"file": "dist/color-fn.js",
"format": "esm",
"sourcemap": true,
file: "dist/color-fn.js",
format: "esm",
sourcemap: true,
},
];

// Add minified versions of every bundle
const addMinBundle = (bundles) => {
const addMinBundle = bundles => {
return bundles.flatMap(bundle => {
const minBundle = Object.assign({}, bundle);
minBundle.file = minBundle.file.replace(/\.\w+$/, ".min$&");
Expand Down
3 changes: 1 addition & 2 deletions _build/rollup.legacy.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ export default defaultConfig.map(config =>
file: bundle.file.replace(/\.(?:min\.)?\w+$/, ".legacy$&"),
})),
plugins: [...(config.plugins || []), ...legacyPlugins],
}),
);
}));
36 changes: 20 additions & 16 deletions assets/js/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let colors = {
blue: new Color(root_cs.getPropertyValue("--color-blue")),
};
let supportsP3 = window.CSS && CSS.supports("color", "color(display-p3 0 1 0)");
let interpolationOptions = {steps: 5, space: "lch", outputSpace: supportsP3 ? "p3" : "hsl"};
let interpolationOptions = { steps: 5, space: "lch", outputSpace: supportsP3 ? "p3" : "hsl" };

if (!Color.DEBUGGING) {
let redGreen = colors.red.range(colors.green, interpolationOptions);
Expand All @@ -21,29 +21,33 @@ if (!Color.DEBUGGING) {
...Color.steps(greenBlue, interpolationOptions),
...Color.steps(blueRed, interpolationOptions),
],
"color-red-light": colors.red.clone().set({"lch.l": 80}),
"color-green-light": colors.green.clone().set({"lch.l": 80}),
"color-blue-light": colors.blue.clone().set({"lch.l": 80}),
"color-red-light": colors.red.clone().set({ "lch.l": 80 }),
"color-green-light": colors.green.clone().set({ "lch.l": 80 }),
"color-blue-light": colors.blue.clone().set({ "lch.l": 80 }),

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

"color-red-green": redGreen(.5),
"color-green-blue": greenBlue(.5),
"color-blue-red": blueRed(.5),
"color-red-green": redGreen(0.5),
"color-green-blue": greenBlue(0.5),
"color-blue-red": blueRed(0.5),

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

window.vars = vars;

document.head.insertAdjacentHTML("beforeend",
document.head.insertAdjacentHTML(
"beforeend",
`<style>
:root {
${Object.entries(vars).map(pair => `--${pair[0]}: ${pair[1]}`).join(";")};
${Object.entries(vars)
.map(pair => `--${pair[0]}: ${pair[1]}`)
.join(";")};
}
</style>`);
</style>`,
);
}
6 changes: 4 additions & 2 deletions assets/js/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ if (current) {
function idify (str) {
// from Mavo.Functions.idify()
return str
.normalize("NFD").replace(/[\u0300-\u036f]/g, "") // Convert accented letters to ASCII
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "") // Convert accented letters to ASCII
.replace(/[^\w\s-]/g, "") // Remove remaining non-ASCII characters
.trim().replace(/\s+/g, "-") // Convert whitespace to hyphens
.trim()
.replace(/\s+/g, "-") // Convert whitespace to hyphens
.toLowerCase();
}

Expand Down
5 changes: 4 additions & 1 deletion assets/js/enhance.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ export function styleCallouts (
labels = new RegExp(`(${labels.join("|")}):`);

for (let p of elements) {
let callout = p.textContent.trimLeft().slice(0, maxLabelLength + 2).match(labels)?.[1];
let callout = p.textContent
.trimLeft()
.slice(0, maxLabelLength + 2)
.match(labels)?.[1];

if (callout) {
p.classList.add(callout.toLowerCase());
Expand Down
1 change: 0 additions & 1 deletion assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ if (location.pathname.indexOf("/docs/") > -1 && window.toc) {
}

styleCallouts();

2 changes: 1 addition & 1 deletion color.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ window.Color = window.Color || Color;

// Re-export
export default Color;
export {util};
export { util };
6 changes: 3 additions & 3 deletions data/spaces.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ColorSpace from "../src/spaces/index.js";
import {WHITES} from "../src/adapt.js";
import { WHITES } from "../src/adapt.js";

let whitePoints = Object.entries(WHITES);

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

for (let id in ColorSpace.registry) {
let space = ColorSpace.registry[id];
let meta = spaces[id] = Object.assign(modules.space[id] ?? {}, {
let meta = (spaces[id] = Object.assign(modules.space[id] ?? {}, {
name: space.name,
white: whitePoints.find(([name, white]) => white === space.white)?.[0] ?? "D65",
base: space.base,
coords: space.coords,
});
}));

if (space.id != id) {
meta.aliasOf = ColorSpace.registry[space.id].name;
Expand Down
2 changes: 1 addition & 1 deletion get/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $("a[download]")?.addEventListener("click", evt => {
});

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

return URL.createObjectURL(blob);
}
Expand Down
Loading
Loading