Skip to content

Commit

Permalink
chore: set up eslint 9 and gitattributes
Browse files Browse the repository at this point in the history
The latter for cross-platform support
  • Loading branch information
wkillerud committed Jul 10, 2024
1 parent ac55dcf commit 494e4cd
Show file tree
Hide file tree
Showing 22 changed files with 836 additions and 658 deletions.
7 changes: 0 additions & 7 deletions .eslintignore

This file was deleted.

16 changes: 0 additions & 16 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
29 changes: 29 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import prettierConfig from "eslint-config-prettier";
import prettierPlugin from "eslint-plugin-prettier/recommended";
import globals from "globals";
import js from "@eslint/js";

export default [
js.configs.recommended,
prettierConfig,
prettierPlugin,
{
languageOptions: {
globals: {
...globals.node,
...globals.browser,
global: true,
},
},
},
{
ignores: [
"tap-snapshots/*",
"node_modules/*",
"modules/*",
"utils/*",
"dist/*",
"tmp/*",
],
},
];
20 changes: 9 additions & 11 deletions fixtures/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
// import _ from 'lodash';

import { h, Component, render } from 'https://unpkg.com/preact?module';
import foo from './module.js';
import { h, render } from "https://unpkg.com/preact?module";
import foo from "./module.js";


function component() {
const element = document.createElement('div');
function component() {
const element = document.createElement("div");

// Lodash, currently included via a script, is required for this line to work
// Lodash, now imported by this script
element.innerHTML = ['Hello', 'webpack', foo()].join(' ');

element.innerHTML = ["Hello", "webpack", foo()].join(" ");

// Create your app
const app = h('h1', null, 'Hello World!');
const app = h("h1", null, "Hello World!");

render(app, document.body);

return element;
}
return element;
}

document.body.appendChild(component());
document.body.appendChild(component());
6 changes: 3 additions & 3 deletions fixtures/module.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const foo = () => {
return 'foo';
}
return "foo";
};

export default foo
export default foo;
4 changes: 2 additions & 2 deletions fixtures/modules/basic/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { html } from 'lit-element';
import { html } from "lit-element";

const render = (world) => {
return html`<p>Hello ${world}!</p>`;
return html`<p>Hello ${world}!</p>`;
};
render();
24 changes: 15 additions & 9 deletions fixtures/modules/file/main.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { html } from 'lit-html/lit-html';
import { css } from 'lit-html';
import { LitElement } from 'lit-element';
import { html } from "lit-html/lit-html";
import { css } from "lit-html";
import { LitElement } from "lit-element";

export default class Inner extends LitElement {
static get styles() {
return [css`:host { color: red; }`];
}
static get styles() {
return [
css`
:host {
color: red;
}
`,
];
}

render(world) {
return html`<p>Hello ${world}!</p>`;
}
render(world) {
return html`<p>Hello ${world}!</p>`;
}
}
32 changes: 16 additions & 16 deletions fixtures/modules/simple/app/app.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { replaceElement } from '../utils/dom.js';
import view from './views.js';
import data from '../data/data.js';
import { replaceElement } from "../utils/dom.js";
import view from "./views.js";
import data from "../data/data.js";

export default class App {
constructor(root) {
this.root = root;
}
constructor(root) {
this.root = root;
}

render() {
const items = data();
const el = view(items);
this.root = replaceElement(this.root, el);
}
render() {
const items = data();
const el = view(items);
this.root = replaceElement(this.root, el);
}

update() {
setInterval(() => {
this.render();
}, 1000);
}
update() {
setInterval(() => {
this.render();
}, 1000);
}
}
4 changes: 2 additions & 2 deletions fixtures/modules/simple/app/views.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { html, css } from 'lit-element';
import { html } from "lit-element";

export default function view(items) {
return html`<p>Hello ${items[0]}!</p>`;
return html`<p>Hello ${items[0]}!</p>`;
}
16 changes: 8 additions & 8 deletions fixtures/modules/simple/data/data.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
function random(min, max) {
return Math.floor(min + Math.random() * (max + 1 - min));
return Math.floor(min + Math.random() * (max + 1 - min));
}

export default function data() {
return [
random(0, 20),
random(20, 40),
random(40, 60),
random(60, 80),
random(80, 100),
];
return [
random(0, 20),
random(20, 40),
random(40, 60),
random(60, 80),
random(80, 100),
];
}
22 changes: 11 additions & 11 deletions fixtures/modules/simple/main.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { firstElement } from './utils/dom.js';
import App from './app/app.js';
import { firstElement } from "./utils/dom.js";
import App from "./app/app.js";

const ready = () => {
return new Promise((resolve) => {
document.addEventListener('DOMContentLoaded', () => {
const el = document.getElementById('app');
resolve(firstElement(el));
});
return new Promise((resolve) => {
document.addEventListener("DOMContentLoaded", () => {
const el = document.getElementById("app");
resolve(firstElement(el));
});
});
};

const start = async () => {
const el = await ready();
const app = new App(el);
app.render();
app.update();
const el = await ready();
const app = new App(el);
app.render();
app.update();
};
start();
6 changes: 3 additions & 3 deletions fixtures/modules/simple/utils/dom.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export function replaceElement(target, element) {
target.replaceWith(element);
return element;
target.replaceWith(element);
return element;
}

export function firstElement(element) {
return element.firstElementChild;
return element.firstElementChild;
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"scripts": {
"test": "tap --no-coverage",
"test:snapshot": "TAP_SNAPSHOT=1 tap --no-coverage",
"lint": "eslint . --ext=js,cjs",
"lint:fix": "eslint . --fix --ext=js,cjs"
"lint": "eslint ."
},
"repository": {
"type": "git",
Expand All @@ -36,10 +35,11 @@
"@semantic-release/git": "10.0.1",
"webpack": "5.91.0",
"webpack-cli": "5.1.4",
"eslint": "8.57.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-plugin-import": "2.29.1",
"eslint": "9.6.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.1.3",
"fastify": "4.28.1",
"globals": "15.8.0",
"semantic-release": "21.1.2",
"tap": "16.3.10",
"memfs": "4.9.3"
Expand Down
39 changes: 18 additions & 21 deletions release.config.cjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
module.exports = {
plugins: [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
'@semantic-release/changelog',
[
'@semantic-release/npm',
{
tarballDir: 'release',
},
],
[
'@semantic-release/github',
{
assets: 'release/*.tgz',
},
],
'@semantic-release/git',
plugins: [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
[
"@semantic-release/npm",
{
tarballDir: "release",
},
],
preset: 'angular',
branches: [
{ name: 'main' },
{ name: 'next', prerelease: true },
[
"@semantic-release/github",
{
assets: "release/*.tgz",
},
],
"@semantic-release/git",
],
preset: "angular",
branches: [{ name: "main" }, { name: "next", prerelease: true }],
};
59 changes: 31 additions & 28 deletions src/builders.cjs
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
const parsers = require('./parsers.cjs');
const parsers = require("./parsers.cjs");

const RX_SIDE_EFFECTS_IMPORT = parsers.sideEffectsImport();
const RX_STANDARD_IMPORT = parsers.standardImport();
const RX_DYNAMIC_IMPORT = parsers.dynamicImport();

const standardImport = ({ dictionary = new Map(), source = '' }) => {
const result = source.replace(RX_STANDARD_IMPORT, (replacer, g1, g2, g3, g4) => {
const dep = dictionary.get(g4) || g4;
return `${g1} ${g2} ${g3} '${dep}'`;
});
const standardImport = ({ dictionary = new Map(), source = "" }) => {
const result = source.replace(
RX_STANDARD_IMPORT,
(replacer, g1, g2, g3, g4) => {
const dep = dictionary.get(g4) || g4;
return `${g1} ${g2} ${g3} '${dep}'`;
},
);

return {
source: result,
dictionary,
};
return {
source: result,
dictionary,
};
};
module.exports.standardImport = standardImport;

const dynamicImport = ({ dictionary = new Map(), source = '' }) => {
const result = source.replace(RX_DYNAMIC_IMPORT, (replacer, g1, g2) => {
const dep = dictionary.get(g2) || g2;
return `${g1}('${dep}')`;
});
const dynamicImport = ({ dictionary = new Map(), source = "" }) => {
const result = source.replace(RX_DYNAMIC_IMPORT, (replacer, g1, g2) => {
const dep = dictionary.get(g2) || g2;
return `${g1}('${dep}')`;
});

return {
source: result,
dictionary,
};
return {
source: result,
dictionary,
};
};
module.exports.dynamicImport = dynamicImport;

const sideEffectsImport = ({ dictionary = new Map(), source = '' }) => {
const result = source.replace(RX_SIDE_EFFECTS_IMPORT, (replacer, g1, g2) => {
const dep = dictionary.get(g2) || g2;
return `${g1} '${dep}'`;
});
const sideEffectsImport = ({ dictionary = new Map(), source = "" }) => {
const result = source.replace(RX_SIDE_EFFECTS_IMPORT, (replacer, g1, g2) => {
const dep = dictionary.get(g2) || g2;
return `${g1} '${dep}'`;
});

return {
source: result,
dictionary,
};
return {
source: result,
dictionary,
};
};
module.exports.sideEffectsImport = sideEffectsImport;
Loading

0 comments on commit 494e4cd

Please sign in to comment.