DEV Community

Cover image for Adding Code Formatting to Whitebophir Project: A Journey of Contribution
Bhavik Mistry
Bhavik Mistry

Posted on

1

Adding Code Formatting to Whitebophir Project: A Journey of Contribution

My second open-source contribution to the "Whitebophir" project concentrated around introducing code formatting as a means of improving project quality. This blog post explains the actions I took, and the valuable lessons I learned in the process. It emphasizes that contributing to open source goes beyond writing code and highlights how the project can be improved overall.

The Issue

The journey began with a specific issue: Link to Issue #291. I have requested to integrate code formatting into the project and incorporate it into the continuous integration (CI) workflow.

Planning and Setup

Install Prettier

Install the Prettier into the machine locally:

npm install --save-dev prettier
Enter fullscreen mode Exit fullscreen mode

Prettier Configuration

The first step was to introduce Prettier, a popular code formatter, to the project. I added a .prettierrc file with the following configurations:

{
  "arrowParens": "always",
  "bracketSpacing": true,
  "embeddedLanguageFormatting": "auto",
  "endOfLine": "lf",
  "insertPragma": false,
  "proseWrap": "preserve",
  "requirePragma": false,
  "tabWidth": 2,
  "useTabs": false,
  "printWidth": 80
}
Enter fullscreen mode Exit fullscreen mode

Ignoring Unnecessary Files

To ensure Prettier didn't interfere with certain files, I created a .prettierignore file:

package.json
package-lock.json
node_modules/
.DS_Store
*.html
Enter fullscreen mode Exit fullscreen mode

Integrating Prettier into Package.json

I updated the package.json file to include Prettier scripts:

"prettier": "prettier . --write",
"prettier-check": "prettier . --check"
Enter fullscreen mode Exit fullscreen mode

Implementation

With the groundwork laid, it was time to incorporate Prettier into the project's CI workflow.

CI Workflow Update

I modified the .github/workflows/CI.yml file to include a step for Prettier:

format:
  runs-on: ubuntu-latest

  steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Install dependencies
      run: npm install

    - name: Run Prettier check
      run: npx prettier --check .

Enter fullscreen mode Exit fullscreen mode

Challenges and Learnings

CI Configuration
Configuring CI workflows can be intricate. I faced challenges in ensuring Prettier worked seamlessly within the CI environment. Debugging and refining the workflow was an enlightening experience.

Pull Request

My pull request, Link to Pull Request #292, encapsulates the entire journey. The addition of code formatting not only improves the project's consistency but also sets the stage for future contributors.

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more