Skip to content

Commit

Permalink
Add ESLint (#1)
Browse files Browse the repository at this point in the history
* Add ESLint

* Refactor

"Synchronize" code with ESLint

* refactor rollup config formatting

* convert config files to js
  • Loading branch information
scripthunter7 authored Feb 21, 2023
1 parent b2a8559 commit 3bb7dae
Show file tree
Hide file tree
Showing 21 changed files with 5,139 additions and 4,087 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
31 changes: 31 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module.exports = {
plugins: ["prettier", "import"],
extends: ["airbnb-base", "prettier", "plugin:import/recommended"],
env: {
node: true,
jest: true,
},
rules: {
"prettier/prettier": "error",
"max-len": [
"error",
{
code: 120,
comments: 120,
tabWidth: 4,
ignoreUrls: false,
ignoreTrailingComments: false,
ignoreComments: false,
},
],
indent: [
"error",
4,
{
SwitchCase: 1,
},
],
"import/extensions": 0,
"import/no-extraneous-dependencies": 0,
},
};
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint
yarn test
6 changes: 0 additions & 6 deletions .prettierrc

This file was deleted.

6 changes: 6 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
tabWidth: 4,
endOfLine: "lf",
printWidth: 120,
singleQuote: false,
};
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,20 @@
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.2.1",
"eslint": "^8.34.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.0",
"jest": "^29.3.1",
"prettier": "^2.8.4",
"rollup": "^3.8.1",
"rollup-plugin-node-externals": "^5.0.3"
},
"scripts": {
"prepare": "husky install",
"lint": "eslint .",
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
"build": "yarn rollup --config rollup.config.js"
}
Expand Down
203 changes: 112 additions & 91 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,112 @@
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import externals from "rollup-plugin-node-externals";
import alias from "@rollup/plugin-alias";
import { getBabelOutputPlugin } from "@rollup/plugin-babel";
import terser from "@rollup/plugin-terser";
import json from "@rollup/plugin-json";

// CommonJS build
const cjs = {
input: "./src/index.js",
output: [
{
file: `./dist/ecsstree.cjs`,
format: "cjs",
exports: "auto",
sourcemap: false,
},
],
plugins: [json(), externals(), commonjs({ sourceMap: false }), resolve({ preferBuiltins: false })],
};

// ECMAScript build
const esm = {
input: "./src/index.js",
output: [
{
file: `./dist/ecsstree.esm.js`,
format: "esm",
sourcemap: false,
},
],
plugins: [json(), externals(), commonjs({ sourceMap: false }), resolve({ preferBuiltins: false })],
};

const browserPlugins = [
json(),
commonjs({ sourceMap: false }),
resolve({ preferBuiltins: false, browser: true }),
alias({
entries: [
{
find: "css-tree",
replacement: "node_modules/css-tree/dist/csstree.esm.js",
},
],
}),
getBabelOutputPlugin({
presets: [
[
"@babel/preset-env",
{
targets: ["> 1%", "not dead"],
},
],
],
allowAllFormats: true,
}),
terser(),
];

// Browser-friendly UMD build
const umd = {
input: "./src/index.js",
output: [
{
file: `./dist/ecsstree.umd.min.js`,
name: "ECSSTree",
format: "umd",
sourcemap: false,
},
],
plugins: browserPlugins,
};

// Browser-friendly IIFE build
const iife = {
input: "./src/index.js",
output: [
{
file: `./dist/ecsstree.iife.min.js`,
name: "ECSSTree",
format: "iife",
sourcemap: false,
},
],
plugins: browserPlugins,
};

// Export build configs for Rollup
export default [cjs, esm, umd, iife];
/* eslint-disable prettier/prettier */
import alias from "@rollup/plugin-alias";
import commonjs from "@rollup/plugin-commonjs";
import externals from "rollup-plugin-node-externals";
import json from "@rollup/plugin-json";
import resolve from "@rollup/plugin-node-resolve";
import terser from "@rollup/plugin-terser";
import { getBabelOutputPlugin } from "@rollup/plugin-babel";

const commonPlugins = [
json(),
commonjs({ sourceMap: false }),
];

// CommonJS build
const cjs = {
input: "./src/index.js",
output: [
{
file: "./dist/ecsstree.cjs",
format: "cjs",
exports: "auto",
sourcemap: false,
},
],
plugins: [
...commonPlugins,
externals(),
resolve({ preferBuiltins: false })
],
};

// ECMAScript build
const esm = {
input: "./src/index.js",
output: [
{
file: "./dist/ecsstree.esm.js",
format: "esm",
sourcemap: false,
},
],
plugins: [
...commonPlugins,
externals(),
resolve({ preferBuiltins: false }),
],
};

const browserPlugins = [
...commonPlugins,
resolve({
preferBuiltins: false,
browser: true
}),
alias({
entries: [
{
find: "css-tree",
replacement: "node_modules/css-tree/dist/csstree.esm.js",
},
],
}),
getBabelOutputPlugin({
presets: [
[
"@babel/preset-env",
{
targets: ["> 1%", "not dead"],
},
],
],
allowAllFormats: true,
}),
terser(),
];

// Browser-friendly UMD build
const umd = {
input: "./src/index.js",
output: [
{
file: "./dist/ecsstree.umd.min.js",
name: "ECSSTree",
format: "umd",
sourcemap: false,
},
],
plugins: browserPlugins,
};

// Browser-friendly IIFE build
const iife = {
input: "./src/index.js",
output: [
{
file: "./dist/ecsstree.iife.min.js",
name: "ECSSTree",
format: "iife",
sourcemap: false,
},
],
plugins: browserPlugins,
};

// Export build configs for Rollup
export default [
cjs,
esm,
umd,
iife
];
80 changes: 40 additions & 40 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import syntax from "./syntax/index.js";

// Fork API doesn't export everything, so we need to export the rest of
// the API manually. See the original source code:
// https://github.com/csstree/csstree/blob/master/lib/index.js

export * from "./version.js";

export {
createSyntax,
List,
Lexer,
tokenTypes,
tokenNames,
TokenStream,
definitionSyntax,
clone,
ident,
string,
url,
} from "css-tree";

// Export the forked syntax (comes from the Fork API)
export const {
tokenize,
parse,
generate,
lexer,
createLexer,

walk,
find,
findLast,
findAll,

toPlainObject,
fromPlainObject,

fork,
} = syntax;
import syntax from "./syntax/index.js";

// Fork API doesn't export everything, so we need to export the rest of
// the API manually. See the original source code:
// https://github.com/csstree/csstree/blob/master/lib/index.js

export { default as version } from "./version.js";

export {
createSyntax,
List,
Lexer,
tokenTypes,
tokenNames,
TokenStream,
definitionSyntax,
clone,
ident,
string,
url,
} from "css-tree";

// Export the forked syntax (comes from the Fork API)
export const {
tokenize,
parse,
generate,
lexer,
createLexer,

walk,
find,
findLast,
findAll,

toPlainObject,
fromPlainObject,

fork,
} = syntax;
Loading

0 comments on commit 3bb7dae

Please sign in to comment.