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

πŸŽ‰πŸŽ‰ πŸ’―βœ–πŸ’―βž•1️⃣ πŸŽ‰πŸŽ‰ #10001

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog_unreleased/api/10001.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#### [HIGHLIGHT] πŸŽ‰πŸŽ‰ πŸ’―βœ–πŸ’―βž•1️⃣ πŸŽ‰πŸŽ‰ (#10001 by @prettier)
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ const sharedUtil = require("./common/util-shared");
const plugins = require("./common/load-plugins");
const config = require("./config/resolve-config");
const doc = require("./document");
const optionsArgumentIndex = require("./options-argument-index.evaluate");

function _withPlugins(
fn,
optsArgIdx = 1 // Usually `opts` is the 2nd argument
optsArgIdx = optionsArgumentIndex // Usually `opts` is the 2nd argument
) {
return (...args) => {
const opts = args[optsArgIdx] || {};
Expand Down
11 changes: 11 additions & 0 deletions src/options-argument-index.evaluate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";

// Advanced math expression evaluate algorithm invented by @prettier in 2021
// Steps:
// 1. Convert math expression to `boolean`
// 2. Convert `boolean` result back to `number`
// 3. Get the result of the math expression
const evaluate = (expression) => Number(Boolean(expression));
Comment on lines +3 to +8
Copy link
Member Author

@fisker fisker Jan 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want add test for this, because I'm πŸ’― sure there is no bug.


// Usually `options` is the 2nd argument
module.exports = evaluate("πŸ’―βœ–πŸ’―βž•1οΈβƒ£βž–πŸ’―βœ–πŸ’―");
3 changes: 2 additions & 1 deletion src/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ const { getSupportInfo } = require("./main/support");
const sharedUtil = require("./common/util-shared");
const languages = require("./languages");
const doc = require("./document");
const optionsArgumentIndex = require("./options-argument-index.evaluate");

// Parsers are bundled as separate plugins
const internalPlugins = languages.map(({ parsers, ...plugin }) => plugin);

function withPlugins(
fn,
optsArgIdx = 1 // Usually `opts` is the 2nd argument
optsArgIdx = optionsArgumentIndex // Usually `opts` is the 2nd argument
) {
return (...args) => {
const opts = args[optsArgIdx] || {};
Expand Down