Skip to content

Commit

Permalink
Continuous Release 1.1.0
Browse files Browse the repository at this point in the history
See pull request #3.
  • Loading branch information
Splines authored Dec 1, 2023
2 parents 1e589c5 + f26939d commit e3c3a99
Show file tree
Hide file tree
Showing 33 changed files with 2,399 additions and 38 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Tests

on:
push:
branches: [main]
pull_request:
types: [opened, reopened, synchronize, ready_for_review]

jobs:
mocha:
name: Mocha
strategy:
matrix:
os: [ubuntu-latest]
node: [16, 17, 18, 19, 20, 21]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Node.js ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm install
env:
CI: true
- name: Run Mocha tests
run: npm test
6 changes: 6 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
"spec": "tests/**/*.js",
"ignore": [
"tests/fixtures/**"
],
}
25 changes: 25 additions & 0 deletions DEV.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Some developer guidelines


## Merge strategies

- Feature branches to `dev`: squash commit
- Continuous Release from `dev` to `main`: standard merge commit
- Hotfixes: branch off `main`, merge PR into `main` via squash commit, then merge back `main` to `dev` via standard merge commit.


## Create a new release (and publish to npm)

As this is only a small project, we haven't automated publishing to the NPM registry yet and instead rely on the following manual workflow.

- Make sure the tests pass locally: `npm test`
- Make another commit on the `dev` branch bumping the npm version in the `package.json`. For that, use:
```sh
npm run bump-version -- [<newversion> | major | minor | patch]
```
- Once the `dev` branch is ready, open a PR (Pull request) called "Continuous Release <version.number>" and give it the "release" label. Merge this PR into `main`.
- Create a new release via the GitHub UI and assign a new tag alongside that.
- Fetch the tag locally (`git fetch`) and publish to npm via `npm run publish-final`. You probably have to login to npm first (`npm login`).
- Enjoy ✌ Check that the release is available [here on npm](https://www.npmjs.com/package/eslint-plugin-erb).


53 changes: 49 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,59 @@ module.exports = {
};
```

If you're wondering what a good starting point for your own `.eslintrc.js` file might be, you can use the config from [here](https://github.com/Splines/eslint-plugin-erb/tree/main/tests#environment).


## Editor Integrations

The [ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) for VSCode has built-in support for the ERB processor once you've configured it in your `.eslintrc.js` file as shown above.

If you're using VSCode, you may find this `settings.json` options useful:
```jsonc
{
//////////////////////////////////////
// JS (ESLint)
//////////////////////////////////////
// https://eslint.style/guide/faq#how-to-auto-format-on-save
// https://github.com/microsoft/vscode-eslint#settings-options
"editor.formatOnSave": true,
"eslint.format.enable": true,
"[javascript]": {
"editor.formatOnSave": false, // to avoid formatting twice (ESLint + VSCode)
"editor.defaultFormatter": "dbaeumer.vscode-eslint" // use ESLint plugin
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true // Auto-fix ESLint errors on save
},
// this disables VSCode built-int formatter (instead we want to use ESLint)
"javascript.validate.enable": false,
//////////////////////////////////////
// Files
//////////////////////////////////////
"files.exclude": {
"node_modules/": false,
},
"files.associations": {
"*.js.erb": "javascript"
},
}
```


## Limitations
- Does not account for code indentation inside `if/else` ERB statements, e.g.
this snippet

## TODO
```js
<% if you_feel_lucky %>
console.log("You are lucky 🍀");
<% end %>
```
will be autofixed to
```js
<% if you_feel_lucky %>
console.log("You are lucky 🍀");
<% end %>
```

- [ ] Add tests
- [ ] Improve in-line documentation
- [ ] Add guide on how to use
- No support for ESLint suggestions (but full support for Autofixes as shown in the GIF above)
14 changes: 0 additions & 14 deletions lib/erb_regex.js

This file was deleted.

15 changes: 13 additions & 2 deletions lib/offset_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ this.lineOffsetLookup = {
21 => Map(1) { 942 => [ 6, 95 ] }
}
For brevity, we emit the respective property names and show the values in an
array instead. First number is line offset, second number is column offset.
this.offsetLookup = {
43 => [ 0, -23 ],
92 => [ 0, -17 ],
Expand All @@ -21,8 +24,16 @@ this.offsetLookup = {
942 => [ 6, 95 ]
}
Each index stored corresponds to an "end index" of the respective ERB tag,
but when it it processed already, i. e. replaced by a dummy comment.
We store the end index of the respective ERB tag and use that as key for our map.
Note that this end index refers to the processed text, i. e. the text after
replacing ERB tags with dummy comments.
The index is an index to the whole text.
Note that line offsets accumulate.
And to add to the good old off-by-one confusion:
Line offsets: 1-based
Column offsets: 0-based
(also see file coordinates)
*/

Expand Down
6 changes: 3 additions & 3 deletions lib/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
const cache = require("./cache.js");

const { indexToColumn } = require("./file_coordinates.js");
const regex = require("./erb_regex.js");

// how annoying is that kind of important in JS ?!
// how annoying is that kind of import in JS ?!
var OffsetMap = require("./offset_map.js").OffsetMap;

const erbRegex = /<%[\s\S]*?%>/g;
const DUMMY_STR = "/* eslint-disable */{}/* eslint-enable */";
const DUMMY_LEN = DUMMY_STR.length;

Expand All @@ -29,7 +29,7 @@ function preprocess(text, filename) {
let numDiffChars = 0;
const offsetMap = new OffsetMap();

while ((match = regex.erbRegexChained.exec(text)) !== null) {
while ((match = erbRegex.exec(text)) !== null) {
// Match information
const startIndex = match.index;
const matchText = match[0];
Expand Down
18 changes: 16 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-erb",
"version": "1.0.2-0",
"version": "1.1.0",
"description": "An ESLint plugin to lint JavaScript in ERB files (.js.erb)",
"license": "MIT",
"author": {
Expand All @@ -14,15 +14,29 @@
"keywords": [
"eslint",
"eslintplugin",
"eslint-processor",
"erb",
"ruby",
"embedded ruby",
"javascript",
"lint",
"linter"
],
"main": "index.js",
"files": [
"index.js",
"lib"
],
"devDependencies": {
"@stylistic/eslint-plugin": "^1.3.3",
"eslint": "^8.54.0"
"chai": "^4.3.10",
"eslint": "^8.54.0",
"mocha": "^10.2.0"
},
"scripts": {
"test": "mocha",
"whats-included": "npm pack --dry-run",
"bump-version": "npm run test && npm version --no-git-tag-version",
"publish-final": "npm run test && npm publish"
}
}
2 changes: 2 additions & 0 deletions tests/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
env:
mocha: true
67 changes: 67 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Testing


## Run tests

```sh
npm test
```


## Environment

For reproduction, this is the ESLint configuration file used to generate the input messages for testing (see the `tests/fixtures/` folder. The files were manually renamed to end with `.js.erb` during this process.

```js
// .eslintrc.js
// Starting with v9, this config will be deprecated in favor of the new
// configuration files [1]. @stylistic is already ready for the new "flat config",
// when it's time, copy the new config from [2].
// [1] https://eslint.org/docs/latest/use/configure/configuration-files-new
// [2] https://eslint.style/guide/config-presets#configuration-factory

// //////////////////////////////////////////
// Stylistic Plugin for ESLint
// //////////////////////////////////////////
// see the rules in [3] and [4].
// [3] https://eslint.style/packages/js#rules
// [4] https://eslint.org/docs/rules/

// eslint-disable-next-line no-undef
require("@stylistic/eslint-plugin");

// eslint-disable-next-line no-undef
module.exports = {
"root": true,
"parserOptions": {
"ecmaVersion": 2024,
"sourceType": "module"
},
"env": {
"browser": true,
"jquery": true,
"es6": true
},
"plugins": [
"@stylistic",
"erb"
],
"extends": [
"eslint:recommended",
"plugin:@stylistic/all-extends",
"plugin:erb/recommended"
],
"rules": {
"no-unused-vars": "warn",
"@stylistic/indent": ["error", 2],
"@stylistic/quotes": ["error", "double"],
"@stylistic/array-element-newline": ["error", "consistent"],
"@stylistic/max-len": [
"error", {
"code": 100,
"ignoreUrls": true
}
]
}
};
```
Loading

0 comments on commit e3c3a99

Please sign in to comment.