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

Unstable formatting of multi-line expression #7486

Closed
robx opened this issue Jan 30, 2020 · 3 comments
Closed

Unstable formatting of multi-line expression #7486

robx opened this issue Jan 30, 2020 · 3 comments
Labels
area:idempotency Issues with re-printing Prettier’s output lang:javascript Issues affecting JS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program

Comments

@robx
Copy link

robx commented Jan 30, 2020

Prettier 1.19.1
Playground link

--parser babel
--use-tabs

Input:

//
// パズル固有スクリプト部 へびいちご版 hebi.js
//
(function(pidlist, classbase){
        if(typeof module==='object' && module.exports){module.exports = [pidlist, classbase];}
        else{ pzpr.classmgr.makeCustom(pidlist, classbase);}
}(
['hebi'], {
//---------------------------------------------------------
// 画像表示系
Graphic:{
        hideHatena : true,

        gridcolor_type : "LIGHT",

        fgcellcolor_func : "qnum",
        fontShadecolor : "white",
        numbercolor_func : "fixed_shaded",

        getBorderColor : function(border){
                if(!this.puzzle.getConfig('snakebd')){ return false;}

                var cell1 = border.sidecell[0], cell2 = border.sidecell[1];
                if(!cell1.isnull && !cell2.isnull &&
                   (cell1.qnum===-1 && cell2.qnum===-1) &&
                   (cell1.anum!==-1 || cell2.anum!==-1) &&
                   ( ((cell1.anum===-1)!==(cell2.anum===-1)) || (Math.abs(cell1.anum-cell2.anum)!==1)) )
                {
                        return (((!cell1.trial&&cell1.anum!==-1)||(!cell2.trial&&cell2.anum!==-1)) ? this.qanscolor : this.trialcolor);
                }
                return null;
        }
}
}));

Output:

//
// パズル固有スクリプト部 へびいちご版 hebi.js
//
(function(pidlist, classbase) {
	if (typeof module === "object" && module.exports) {
		module.exports = [pidlist, classbase];
	} else {
		pzpr.classmgr.makeCustom(pidlist, classbase);
	}
})(["hebi"], {
	//---------------------------------------------------------
	// 画像表示系
	Graphic: {
		hideHatena: true,

		gridcolor_type: "LIGHT",

		fgcellcolor_func: "qnum",
		fontShadecolor: "white",
		numbercolor_func: "fixed_shaded",

		getBorderColor: function(border) {
			if (!this.puzzle.getConfig("snakebd")) {
				return false;
			}

			var cell1 = border.sidecell[0],
				cell2 = border.sidecell[1];
			if (
				!cell1.isnull &&
				!cell2.isnull &&
				cell1.qnum === -1 && cell2.qnum === -1 &&
				(cell1.anum !== -1 || cell2.anum !== -1) &&
				((cell1.anum === -1) !== (cell2.anum === -1) ||
					Math.abs(cell1.anum - cell2.anum) !== 1)
			) {
				return (!cell1.trial && cell1.anum !== -1) ||
					(!cell2.trial && cell2.anum !== -1)
					? this.qanscolor
					: this.trialcolor;
			}
			return null;
		}
	}
});

Iterated output: (extra line-break in long condition)

//
// パズル固有スクリプト部 へびいちご版 hebi.js
//
(function(pidlist, classbase) {
	if (typeof module === "object" && module.exports) {
		module.exports = [pidlist, classbase];
	} else {
		pzpr.classmgr.makeCustom(pidlist, classbase);
	}
})(["hebi"], {
	//---------------------------------------------------------
	// 画像表示系
	Graphic: {
		hideHatena: true,

		gridcolor_type: "LIGHT",

		fgcellcolor_func: "qnum",
		fontShadecolor: "white",
		numbercolor_func: "fixed_shaded",

		getBorderColor: function(border) {
			if (!this.puzzle.getConfig("snakebd")) {
				return false;
			}

			var cell1 = border.sidecell[0],
				cell2 = border.sidecell[1];
			if (
				!cell1.isnull &&
				!cell2.isnull &&
				cell1.qnum === -1 &&
				cell2.qnum === -1 &&
				(cell1.anum !== -1 || cell2.anum !== -1) &&
				((cell1.anum === -1) !== (cell2.anum === -1) ||
					Math.abs(cell1.anum - cell2.anum) !== 1)
			) {
				return (!cell1.trial && cell1.anum !== -1) ||
					(!cell2.trial && cell2.anum !== -1)
					? this.qanscolor
					: this.trialcolor;
			}
			return null;
		}
	}
});

Expected behavior:
No change between first and second run.

@alexander-akait alexander-akait added area:idempotency Issues with re-printing Prettier’s output lang:javascript Issues affecting JS type:bug Issues identifying ugly output, or a defect in the program labels Jan 30, 2020
@alexander-akait
Copy link
Member

Thanks for the issue

@thorn0
Copy link
Member

thorn0 commented Jan 30, 2020

This has been fixed by #7026, but not yet released. Try it on the playground for the upcoming release.

@thorn0 thorn0 closed this as completed Jan 30, 2020
@robx
Copy link
Author

robx commented Jan 30, 2020

Oh, great! Apologies for not checking the development version. Looking forward to the new release then.

@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label May 5, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:idempotency Issues with re-printing Prettier’s output lang:javascript Issues affecting JS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

No branches or pull requests

3 participants