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

Install Prettier For Automatic Code Formatting (JS, HTML, & SCSS) #146

Merged
merged 11 commits into from
Jan 10, 2025

Conversation

vkoves
Copy link
Owner

@vkoves vkoves commented Jan 8, 2025

Description

Installed Prettier, following the docs. I ran it leaving the defaults on and everything seemed generally fine except quotes (the default is double quotes). This also applies to SCSS, so I think this should remove the need for Stylelint. Here's a simple demo:

Before (w/ spacing issues) After Linting (all fixed)
Screenshot from 2025-01-07 21-49-50 Screenshot from 2025-01-07 21-50-00

I've also:

  • Updated the GitHub action, so it checks Prettier is happy and run
  • Updated the existing linting commands, so yarn lint and yarn lint-fix run both ESLint & then Prettier

Fixes #93

Testing Instructions

Prettier is pretty well tested, so just spot check the code and make sure the changes make sense, but mainly poke around the app and make sure everything still looks fine. To test locally, mess up some spacing, and run yarn lint to see errors or yarn lint-fix to fix them!

Additionally, I confirmed having pending Prettier changes fails CI - see commit 8d40de9 near the bottom, which I pushed up without running yarn lint-fix.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@vkoves vkoves added the frontend Frontend/UI work label Jan 8, 2025
Copy link

netlify bot commented Jan 8, 2025

Deploy Preview for radiant-cucurucho-d09bae ready!

Name Link
🔨 Latest commit 038afac
🔍 Latest deploy log https://app.netlify.com/sites/radiant-cucurucho-d09bae/deploys/678090ccbc03dc0008e7c7d5
😎 Deploy Preview https://deploy-preview-146--radiant-cucurucho-d09bae.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

ESLint found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

// 1155 E 60th St
'136212': {owner: BuildingOwners.uchicago.key},
"136212": { owner: BuildingOwners.uchicago.key },
Copy link
Owner Author

Choose a reason for hiding this comment

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

God bless automation cleaning up this giant file 😆

@@ -128,7 +110,9 @@
// A column is empty if it's all empty string or '0', so skip it if so. Some columns switch
// between both, like Natural Gas Use on Merch Mart, which we also want to ignore
return !this.historicBenchmarks.every((datum) => {
return (datum as any)[colKey] === '' || (datum as any)[colKey] === '0.0';
return (
(datum as any)[colKey] === '' || (datum as any)[colKey] === '0.0'

Check warning

Code scanning / ESLint

Disallow the `any` type Warning

Unexpected any. Specify a different type.

Copilot Autofix AI about 20 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

@@ -128,7 +110,9 @@
// A column is empty if it's all empty string or '0', so skip it if so. Some columns switch
// between both, like Natural Gas Use on Merch Mart, which we also want to ignore
return !this.historicBenchmarks.every((datum) => {
return (datum as any)[colKey] === '' || (datum as any)[colKey] === '0.0';
return (
(datum as any)[colKey] === '' || (datum as any)[colKey] === '0.0'

Check warning

Code scanning / ESLint

Disallow the `any` type Warning

Unexpected any. Specify a different type.

Copilot Autofix AI about 20 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

class="unit"
v-html="' ' + unit"
/>
<span v-if="unit" class="unit" v-html="' ' + unit" />

Check warning

Code scanning / ESLint

disallow use of v-html to prevent XSS attack Warning

'v-html' directive can lead to XSS attack.
class="unit"
v-html="unit"
/>
{{ statValue }} <span class="unit" v-html="unit" />

Check warning

Code scanning / ESLint

disallow use of v-html to prevent XSS attack Warning

'v-html' directive can lead to XSS attack.
class="label"
v-html="graphTitle"
/>
<div class="label" v-html="graphTitle" />

Check warning

Code scanning / ESLint

disallow use of v-html to prevent XSS attack Warning

'v-html' directive can lead to XSS attack.
mapPopup: any,
googleMapsSearchInput: any,
mapPopup: any;
googleMapsSearchInput: any;

Check warning

Code scanning / ESLint

Disallow the `any` type Warning

Unexpected any. Specify a different type.

Copilot Autofix AI about 20 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

this.Leaflet.marker(coordinates, MarkerOptions)
.addTo(this.mainFeatureGroup!);
this.Leaflet.marker(coordinates, MarkerOptions).addTo(
this.mainFeatureGroup!,

Check warning

Code scanning / ESLint

Disallow non-null assertions using the `!` postfix operator Warning

Forbidden non-null assertion.

Copilot Autofix AI about 20 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

const SearchRadiusMeters =
MapPage.OneMileInMeters * this.formSearchDistanceMiles;
this.Leaflet.circle(coordinates, { radius: SearchRadiusMeters }).addTo(
this.mainFeatureGroup!,

Check warning

Code scanning / ESLint

Disallow non-null assertions using the `!` postfix operator Warning

Forbidden non-null assertion.

Copilot Autofix AI about 20 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

const marker = this.Leaflet.marker(buildingCoords, MarkerOptions)
.addTo(this.mainFeatureGroup!);
const marker = this.Leaflet.marker(buildingCoords, MarkerOptions).addTo(
this.mainFeatureGroup!,

Check warning

Code scanning / ESLint

Disallow non-null assertions using the `!` postfix operator Warning

Forbidden non-null assertion.

Copilot Autofix AI about 20 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

} as any);
});
maxWidth: 'auto',
} as any,

Check warning

Code scanning / ESLint

Disallow the `any` type Warning

Unexpected any. Specify a different type.

Copilot Autofix AI about 20 hours ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

@vkoves vkoves changed the title Install prettier Install Prettier For Automatic Code Formatting (JS, HTML, & SCSS) Jan 8, 2025
@vkoves vkoves marked this pull request as ready for review January 8, 2025 04:14
@@ -1699,12 +1707,15 @@ export const BuildingsCustomInfo: { [buildingId: string]: IBuildingCustomInfo }
// 162 North State Street
'250167': { owner: BuildingOwners.saic.key },
// 280 Building, 280 S Columbus Dr
'2tags: [ BuildingTags.hasRetrofitCaseStudy],52065': { owner: BuildingOwners.saic.key ,
'2tags: [ BuildingTags.hasRetrofitCaseStudy],52065': {
Copy link
Owner Author

Choose a reason for hiding this comment

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

TODO: Fix this line, this looks derped

@vkoves
Copy link
Owner Author

vkoves commented Jan 10, 2025

A happy coincidence, I didn't run linting in 8d40de9, and thus confirmed Prettier works in CI 🎉

Note that commit fixes a building (280 N Columbus) not being associated with its retrofit report or its owner. Here's after the fix:

Screenshot from 2025-01-09 21-18-58

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

Copy link

@hkier hkier left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Copy link

@hkier hkier left a comment

Choose a reason for hiding this comment

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

looks good to me.

@vkoves vkoves merged commit 4b831c4 into main Jan 10, 2025
7 checks passed
@vkoves vkoves deleted the install-prettier branch January 10, 2025 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend Frontend/UI work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Style Linting Via ESLint/Prettier & Stylelint to Enforce Formatting
2 participants