Skip to content

Commit

Permalink
feat: add recommended config (#1)
Browse files Browse the repository at this point in the history
Also, setup vitest and esbuild, along with some tests.
  • Loading branch information
skyrpex authored Apr 21, 2022
1 parent fa54847 commit 42a6522
Show file tree
Hide file tree
Showing 29 changed files with 1,118 additions and 2,278 deletions.
1 change: 0 additions & 1 deletion .gitattributes

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

3 changes: 0 additions & 3 deletions .gitignore

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

3 changes: 0 additions & 3 deletions .npmignore

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

49 changes: 6 additions & 43 deletions .projen/deps.json

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

33 changes: 12 additions & 21 deletions .projen/tasks.json

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

52 changes: 33 additions & 19 deletions .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,12 @@ const project = new typescript.TypeScriptProject({
name: "@cloudy-ts/eslint-plugin",

deps: [],
devDeps: [
"eslint",
"@types/eslint",
"esbuild",
"rollup",
"rollup-plugin-esbuild",
"rollup-plugin-dts",
"@rollup/plugin-node-resolve",
"@rollup/plugin-commonjs",
"@rollup/plugin-json",
"@rollup/plugin-alias",
],
peerDeps: ["eslint"],
devDeps: ["eslint", "@types/eslint"],

prettier: true,

// ESM.
entrypoint: "lib/index.cjs",
entrypointTypes: "",
tsconfig: {
compilerOptions: {
lib: ["ES2020"],
Expand All @@ -31,24 +21,48 @@ const project = new typescript.TypeScriptProject({
},
},

minNodeVersion: "14.18.0",
// Lint.
prettier: true,

// Test.
jest: false,

releaseToNpm: true,
npmAccess: javascript.NpmAccess.PUBLIC,
minNodeVersion: "14.18.0",
});

// ESM.
project.addFields({
type: "module",
exports: {
".": {
require: "./lib/index.cjs",
import: `./lib/index.js`,
types: "./lib/index.d.ts",
},
},
});

// project.compileTask.exec("rollup -c");
// project.watchTask.prependExec("rollup -c --watch");
// project.addTask("dev", { exec: "rollup -c --watch" });
// Build.
project.addDevDeps("esbuild");
project.compileTask.reset();
project.compileTask.prependExec(
"esbuild src/index.ts --bundle --target=es2020 --platform=node --format=esm --outfile=lib/index.js"
);
project.compileTask.prependExec(
"esbuild src/index.ts --bundle --target=es2020 --platform=node --format=cjs --outfile=lib/index.cjs"
);

// Test.
project.addDevDeps("vitest", "c8");
project.testTask.exec("vitest test/rules --passWithNoTests --coverage --run");

project.compileTask.prependExec(
"yarn link && cd ./test/test-app && yarn && yarn link @cloudy-ts/eslint-plugin"
);
project.testTask.exec("vitest test/test-app/index.test.ts --run");

project.watchTask.reset();
project.watchTask.exec("vitest test/rules --passWithNoTests --coverage");

project.synth();
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
# replace this
# @cloudy-ts/eslint-plugin

ESLint plugin that provides a rule to enforce explicit `.js` or `.json` extensions on imports.

[![NPM version](https://img.shields.io/npm/v/@cloudy-ts/eslint-plugin/latest.svg)](https://www.npmjs.com/package/@cloudy-ts/eslint-plugin)
[![NPM downloads](https://img.shields.io/npm/dm/@cloudy-ts/eslint-plugin.svg)](https://www.npmjs.com/package/@cloudy-ts/eslint-plugin)
[![Build status](https://img.shields.io/github/workflow/status/skyrpex/cloudy-ts-eslint-plugin/release)](https://www.npmjs.com/package/@cloudy-ts/eslint-plugin)

## Installation

```sh
yarn add @cloudy-ts/eslint-plugin -D
```

## Usage

Extend from the recommended configuration in your ESLint configuration file (ie, in your `package.json` file):

```json
{
"name": "my-awesome-project",
"eslintConfig": {
"extends": "plugin:@cloudy-ts/recommended"
}
}
```

## Rules

Each rule has emojis denoting:

- ✅ if it belongs to the `recommended` configuration
- 🔧 if some problems reported by the rule are automatically fixable by the `--fix` [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) option
- 💡 if some problems reported by the rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions)

| Name                                         | Description || 🔧 | 💡 |
| :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------- | :-- | :-- | :-- |
| [extensions](docs/rules/extensions.md) | Enforce import and export file extensions. || 🔧 | 💡 |

## Motivation
21 changes: 21 additions & 0 deletions docs/rules/extensions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Enforce import and export file extensions

In ESM, import paths and export paths must contain the file extension in it. This rule suggests and fixes the imports for you.

## Fail

```js
import { add } from "./math";

import { add } from "./math.ts";

import pkg from "./package";
```

## Pass

```js
import { add } from "./math.js";

import pkg from "./package.json";
```
Loading

0 comments on commit 42a6522

Please sign in to comment.