Skip to content

timothyjmorris/provenir-linter

Repository files navigation

Provenir Script Linter & Formatter

A local web tool for linting and formatting Rhino JavaScript code with ESLint and js-beautify, using a few specialized rules created Provenir problems.

Quick Setup

  1. Install Node.js from (Download here)
  2. Clone repository: https://github.com/timothyjmorris/provenir-linter.git
  3. Open terminal/command prompt in that folder
  4. Install Dependencies, run: npm install
  5. Start the Express server, run: npm start
  6. Bookmark http://localhost:3000 and http://localhost:3000/style-guide

To stop the server, press Ctrl+C in the terminal.

How to Use the App

  1. Paste your code into the left panel
  2. Click "Lint & Format" button (or press Ctrl+Enter)
  3. Review issues in the results panel below
  4. Copy formatted code from the right panel back to Provenir
  5. Check Style Guide for MAC team specific best practices

Features

  • Full ESLint integration with custom rules
  • js-beautify formatting with tab indentation
  • Custom Provenir rules for platform-specific quirks
  • Side-by-side code comparison using CodeMirror
  • Detailed issue descriptions with links to documentation
  • Auto-fix indicators & summary
  • Integrated Style Guide with Provenir best practices
  • Responsive design (works on any screen size)
  • Keyboard shortcuts (Ctrl+Enter to format)
  • One-click copy to clipboard

Custom Provenir Rules

This linter includes special rules for Provenir quirks:

  1. provenir/prefer-loose-equality-for-isnull (error)

    • Custom eqeqeq rule that enforces == instead of === for Provenir.isNull() comparisons (and allows null comparisons and typeof checks)
    • Auto-fixes === to ==
  2. provenir/require-comparison-for-isnull (warning)

    • Require explicit == true or == false comparison for Provenir.isNull()
  3. provenir/no-direct-script-return-coercion (warning)

    • Warns against direct type coercion on script returns
    • Example: Number(config.Business_Logic...()) should be offloaded first
  4. provenir/no-unused-vars-except-main (error)

    • Ignores outter function wrapper required by Provenir scripts
  5. provenir/eqeqeq-except-provenir

    • Require === except for Provenir.isNull() comparisons
  6. provenir/require-return-statement

    • Require all wrapper and child functions to have a return.
  7. And a bonus function convertQuotesToDouble() in server.js

    • Converts single quotes to double quotes
    • Preserves single quotes inside strings (for XPath, etc.)
    • Runs after beautification

Notes

  • The server runs locally on your machine (no internet required after setup)
  • Your code never leaves your computer
  • All formatting/linting happens instantly
  • Works with all Provenir-specific globals (Provenir, DocumentHelper, config, etc.)
  • Tab indentation per your style guide
  • Enforces MAC team best practices automatically
  • Blank line preservation: js-beautify automatically pads blank lines with 4 spaces to ensure Provenir Studio preserves visual spacing when you paste formatted code

Troubleshooting

Port already in use? or can't start?

  • Run Stop-Process -Name node -Force 2>$null; Start-Sleep -Seconds 1; npm start
  • Change the PORT in server.js (line 13) to something else like 3001

Can't connect?

  • Make sure the server is running (npm start)
  • Check you're going to the correct URL (http://localhost:3000)

Installation errors?

  • Make sure you have Node.js 18 or higher: node --version
  • Try deleting node_modules folder and running npm install again

Updating Rules

To update ESLint rules or beautify settings:

  1. Edit eslint.config.mjs or .jsbeautifyrc
  2. Edit custom Provenir rules in eslint-rules/provenir-rules.js
  3. Update style guide in style-guide.md
  4. Restart the server (Ctrl+C then npm start)
  5. Refresh the browser

Made with ❤️ for the MAC team

About

Custom Rhino Javascript Linter and Formatter for Provenir Scripts

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •