walkermatt / ol-layerswitcher

Layer control for OpenLayers
MIT License
387 stars 176 forks source link

ESLint & Prettier rules #362

Closed petergoulborn closed 4 years ago

petergoulborn commented 4 years ago

Re-format all files using the following Prettier rules:

    "tabWidth": 2,
    "singleQuote": true,
    "trailingComma": "none",
    "quoteProps": "consistent"

Added ES Lint & Prettier to ensure consistent code formatting and validity. Based on OpenLayers ESLint config from https://github.com/openlayers/eslint-config-openlayers.

Added missing JSDoc comments to ol-layerswitcher.js.

Note: Prettier singleQuote, quoteProps and bracketSpacing are all specified twice to ensure Prettier executions (and code editor integrations) agree with those of ESLlint. (All these are set in OpenLayers ESLint config, which I think goes against Prettier best practice as of v2.0.)

Created lint and format npm scripts and include lint in build: lint runs Prettier and ESLint checks, format will automatically fix problems where possible.

petergoulborn commented 4 years ago

@walkermatt At the current time, npm run lint will fail due to unresolved OpenLayers (ol) dependency. I have a commit pending with OpenLayers added as a dev dependency which will fix that, if that's okay with you?

walkermatt commented 4 years ago

@devsupportman yep, that sounds fine. Thanks for your work on this

walkermatt commented 4 years ago

Running prettier in the doc script resolves the issue inconsistent formatting:

diff --git a/package.json b/package.json
index d152622..b7cf7a1 100644
--- a/package.json
+++ b/package.json
@@ -26,7 +26,7 @@
   },
   "scripts": {
     "watch": "chokidar 'src/**' --initial --command 'WATCH=1 npm run build'",
-    "doc": "documentation readme src/ol-layerswitcher.js --section=API",
+    "doc": "documentation readme src/ol-layerswitcher.js --section=API && prettier --write README.md",
     "lint": "prettier --check . && eslint src examples",
     "format": "prettier --write . && eslint --fix src examples",
     "build": "npm run lint && rollup --config rollup.config.js"
walkermatt commented 4 years ago

Thanks @devsupportman, I've squashed the commits and made a small change to the doc npm script to avoid documentation outputting the API doc diff each time it runs. Closed in 9602306 :tada: