Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure eslint and prettiier #35

Merged
merged 10 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn lint-staged --verbose --config ./.lintstagedrc.json
3 changes: 3 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"*.{js,ts,md}": "eslint --fix"
}
10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# yarn
.yarn
.yarnrc
.yarnrc.yml

# Changelog
CHANGELOG.md

# Templates dir
templates
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"arrowParens": "avoid",
"printWidth": 120,
"tabWidth": 2,
"trailingComma": "all"
}
23 changes: 13 additions & 10 deletions contributors/RFC-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ Also, receiving an array instead of strings give the template itself more contro
Important to note that named arguments could use any arbitrary name. Because of that, we have to provide default values to all those arguments, otherwise missing values would be parsed as the string "undefined". Because we don't know what are the expected names for each template expects.

## Things to note about Template files

### `.mjs` extension

It's important to note the file extension should be `.mjs`. The CLI uses es6 modules, but other packages might use commonjs imports, like Hardhat.

When a package enforces commonjs imports, our templates created within those packages wouldn't work unless we explicitly tell node that it should use es6 imports. Using `.mjs` extensions is the best way we've found to do that.
Expand All @@ -134,21 +136,22 @@ It's a bit annoying having to define an empty array as a default value for all t
As a bonus, using this function will throw an error when an [Args file](#args-file-content) is trying to send an argument with a name not expected by the template.

The way it should be used is as follows:

```js
// file.ext.template.mjs
import { withDefaults } from '../path-to/utils.js'
import { withDefaults } from "../path-to/utils.js";

const contents = ({ foo, bar }) =>
`blah blah
`blah blah
foo value is ${foo}
bar value is ${bar}
blah blah
`
`;

export default withDefaults(contents, {
foo: 'default foo value',
bar: 'default bar value'
})
foo: "default foo value",
bar: "default bar value",
});
```

There's an optional 3rd argument that's for debugging purposes, which is `false` by default. If sent `true`, it will print some information about the arguments received.
Expand All @@ -157,14 +160,14 @@ There's an optional 3rd argument that's for debugging purposes, which is `false`

```js
// file.ext.template.mjs
import { withDefaults } from '../path-to/utils.js'
import { withDefaults } from "../path-to/utils.js";

const contents = ({ foo, bar }) => `${foo} and ${bar}`
const contents = ({ foo, bar }) => `${foo} and ${bar}`;

export default withDefaults(contents, {
foo: 'default',
foo: "default",
// bar: 'not defined!'
})
});

// result: "default and undefined"
```
Expand Down
37 changes: 37 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// @ts-check

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: "./tsconfig.json",
},
},
rules: {
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-argument": "off",
},
},
{
files: ["**/*.js"],
...tseslint.configs.disableTypeChecked,
},
{
ignores: [".changeset", ".yarn", "bin", "dist", "templates"],
},
eslintPluginPrettierRecommended,
{
rules: {
"prettier/prettier": ["warn", { endOfLine: "auto" }],
},
},
);
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
"build": "rollup -c rollup.config.js",
"dev": "rollup -c rollup.config.js --watch",
"cli": "node bin/create-dapp-se2.js",
"lint": "eslint .",
"format": "prettier --write .",
"test": "echo \"Error: no test specified\" && exit 1",
"changeset:release": "yarn build && changeset publish"
"changeset:release": "yarn build && changeset publish",
"postinstall": "husky"
},
"keywords": [
"cli",
Expand All @@ -28,15 +31,23 @@
],
"license": "MIT",
"devDependencies": {
"@eslint/js": "^9.3.0",
"@rollup/plugin-typescript": "11.1.0",
"@types/inquirer": "9.0.3",
"@types/listr": "0.14.4",
"@types/ncp": "2.0.5",
"@types/node": "18.16.0",
"eslint": "^9.3.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"husky": "^9.0.11",
"lint-staged": "^15.2.4",
"prettier": "3.2.5",
"rollup": "3.21.0",
"rollup-plugin-auto-external": "2.0.0",
"tslib": "2.5.0",
"typescript": "5.0.4"
"typescript": "5.0.4",
"typescript-eslint": "^7.10.0"
},
"dependencies": {
"@changesets/cli": "^2.26.2",
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const CURATED_EXTENSIONS: { [key: string]: ExternalExtension } = {
subgraph: {
repository: "https://github.com/scaffold-eth/create-eth-extensions",
branch: "subgraph",
}
}
},
};

export { config, CURATED_EXTENSIONS };
6 changes: 6 additions & 0 deletions src/declarations/merge-pacakges.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module "merge-packages" {
const mergePackages: {
default: (target: string, second: string) => string;
};
export default mergePackages;
}
16 changes: 5 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ export async function createProject(options: Options) {

const currentFileUrl = import.meta.url;

const templateDirectory = path.resolve(
decodeURI(fileURLToPath(currentFileUrl)),
"../../templates"
);
const templateDirectory = path.resolve(decodeURI(fileURLToPath(currentFileUrl)), "../../templates");

const targetDirectory = path.resolve(process.cwd(), options.project);

Expand All @@ -32,10 +29,9 @@ export async function createProject(options: Options) {
},
{
title: `🚀 Creating a new Scaffold-ETH 2 app in ${chalk.green.bold(
options.project
options.project,
)}${options.externalExtension ? ` with the ${chalk.green.bold(getArgumentFromExternalExtensionOption(options.externalExtension))} extension` : ""}`,
task: () =>
copyTemplateFiles(options, templateDirectory, targetDirectory),
task: () => copyTemplateFiles(options, templateDirectory, targetDirectory),
},
{
title: `📦 Installing dependencies with yarn, this could take a while`,
Expand All @@ -56,16 +52,14 @@ export async function createProject(options: Options) {
},
},
{
title: `📡 Initializing Git repository ${
options.extensions.includes("foundry") ? "and submodules" : ""
}`,
title: `📡 Initializing Git repository ${options.extensions.includes("foundry") ? "and submodules" : ""}`,
task: () => createFirstGitCommit(targetDirectory, options),
},
]);

try {
await tasks.run();
renderOutroMessage(options);
await renderOutroMessage(options);
} catch (error) {
console.log("%s Error occurred", chalk.red.bold("ERROR"), error);
console.log("%s Exiting...", chalk.red.bold("Uh oh! 😕 Sorry about that!"));
Expand Down
Loading