Skip to content

Commit

Permalink
refactor: move from extends files to factory function (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
100terres authored Jan 29, 2023
1 parent d01c089 commit 5c4dafc
Show file tree
Hide file tree
Showing 19 changed files with 95 additions and 62 deletions.
12 changes: 8 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = {
root: true,
extends: require.resolve("./js"),
};
const easelint = require("./index");

module.exports = easelint({
javascript: true,
eslint: {
root: true,
},
});
38 changes: 10 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,42 +49,24 @@ Using any [file formats](https://eslint.org/docs/user-guide/configuring/configur
#### Using the full configuration with JavaScript, TypeScript and React

```js
module.exports = {
"extends": ["100terres"],
};
```
#### JavaScript config
const easelint = require('easelint');

```js
module.exports = {
"extends": ["100terres/js"],
};
```
#### JavaScript with React config
module.exports = easelint({
javascript: true,
typescript: true,

```js
module.exports = {
"extends": ["100terres/js", "100terres/jsx"],
};
```
#### TypeScript config
// we currently only support React
jsxPragma: 'react',

```js
module.exports = {
"extends": ["100terres/ts"],
};
```
#### TypeScript with React config
eslint: {
// any eslint configuration
},
});

```js
module.exports = {
"extends": ["100terres/ts", "100terres/tsx"],
};
```

Voilà! Your project now uses a linter.


## How to Contribute 🤝

Pull requests are welcome. If you'd like to contribute to easelint, that's awesome. Simply open an issue explaining what we should change, improve or fix. If we decide that a change is required we can open a pull request and once everything looks good I'll approve and merge the PR.
Expand Down
28 changes: 24 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
module.exports = {
extends: ["./internal/base", "./js", "./jsx", "./ts", "./tsx"].map(
require.resolve
),
const spready = require("@potloc/spready");

module.exports = (config) => {
const { typescript, javascript, jsxPragma, eslint = {} } = config;

if (jsxPragma !== undefined && jsxPragma !== "react") {
throw new Error(
"Only react is supported as a jsx pragma. We'll support more in the feature."
);
}

const react = jsxPragma === "react";

return {
...eslint,
extends: [
"./src/internal/base",
...spready(["./src/js"]).if(javascript),
...spready(["./src/ts"]).if(typescript),
...spready(["./src/jsx"]).if(react && javascript),
...spready(["./src/tsx"]).if(react && typescript),
...spready(() => eslint.extends).if(eslint.extends),
].map(require.resolve),
};
};
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
"LICENSE",
"README.md",
"index.js",
"internal/*",
"js.js",
"jsx.js",
"ts.js",
"tsx.js"
"src/*"
],
"keywords": [
"eslint",
Expand Down Expand Up @@ -56,6 +52,7 @@
}
},
"dependencies": {
"@potloc/spready": "^1.0.0",
"@typescript-eslint/eslint-plugin": "^5.33.0",
"@typescript-eslint/parser": "^5.33.0",
"confusing-browser-globals": "^1.0.11",
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions samples/all/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
module.exports = {
root: true,
extends: require.resolve("../../index"),
};
const easelint = require("../../index");

module.exports = easelint({
javascript: true,
typescript: true,
jsxPragma: "react",
eslint: {
root: true,
},
});
12 changes: 8 additions & 4 deletions samples/js/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = {
root: true,
extends: require.resolve("../../js"),
};
const easelint = require("../../index");

module.exports = easelint({
javascript: true,
eslint: {
root: true,
},
});
13 changes: 9 additions & 4 deletions samples/jsx/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
module.exports = {
root: true,
extends: require.resolve("../../jsx"),
};
const easelint = require("../../index");

module.exports = easelint({
javascript: true,
jsxPragma: "react",
eslint: {
root: true,
},
});
12 changes: 8 additions & 4 deletions samples/ts/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = {
root: true,
extends: require.resolve("../../ts")
};
const easelint = require("../../index");

module.exports = easelint({
typescript: true,
eslint: {
root: true,
},
});
13 changes: 9 additions & 4 deletions samples/tsx/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
module.exports = {
root: true,
extends: require.resolve("../../tsx")
};
const easelint = require("../../index");

module.exports = easelint({
typescript: true,
jsxPragma: "react",
eslint: {
root: true,
},
});
2 changes: 1 addition & 1 deletion internal/base.js → src/internal/base.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
env: {
browser: true,
es2021: true,
es2022: true,
},
parserOptions: {
ecmaVersion: "latest",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 5c4dafc

Please sign in to comment.