Skip to content

Commit

Permalink
Merge pull request #53 from phanect/remove-ts-eslint-dependency
Browse files Browse the repository at this point in the history
Remove typescript-eslint dependency
  • Loading branch information
phanect committed Jul 2, 2022
2 parents 5ab14da + 7424f12 commit 966f1cf
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 9 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use strict";

module.exports = {
//extends: "plugin:@phanect/plain",
root: true,
extends: "phanective/node",

env: {
node: true,
Expand All @@ -11,6 +11,8 @@ module.exports = {
parserOptions: {
ecmaVersion: "latest",
},
//plugins: [ "@phanect" ],
ignorePatterns: [ "test-packages/**" ],
rules: {
"node/no-unpublished-require": "off",
},
};
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ An ESLint plugin to enforce EditorConfig rules
## Install

```bash
$ yarn add --dev eslint eslint-plugin-editorconfig
$ npm install --save-dev eslint eslint-plugin-editorconfig
```

or

```bash
$ npm install --save-dev eslint eslint-plugin-editorconfig
$ yarn add --dev eslint eslint-plugin-editorconfig
```

If you use [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint), you need to install `@typescript-eslint/eslint-plugin` too.

```bash
$ npm install --save-dev @typescript-eslint/eslint-plugin
```

## Usage
Expand Down
12 changes: 10 additions & 2 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ module.exports.buildRule = ({ baseRuleName, description, omitFirstOption, getESL
let baseRule;

if (filename.endsWith(".ts")) {
const { rules } = require("@typescript-eslint/eslint-plugin");
baseRule = rules[baseRuleName] ? klona(rules[baseRuleName]) : jsBaseRule;
try {
const { rules } = require("@typescript-eslint/eslint-plugin");
baseRule = rules[baseRuleName] ? klona(rules[baseRuleName]) : jsBaseRule;
} catch (err) {
if (err.code === "MODULE_NOT_FOUND") {
throw new Error("eslint-plugin-editorconfig requires typescript and @typescript-eslint/eslint-plugin to lint *.ts files. Run `npm install typescript @typescript-eslint/eslint-plugin`.");
} else {
throw err;
}
}
} else {
baseRule = jsBaseRule;
}
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-editorconfig",
"version": "3.2.0",
"version": "4.0.0",
"description": "An ESLint plugin to enforce EditorConfig rules",
"main": "main.js",
"scripts": {
Expand All @@ -24,13 +24,18 @@
},
"homepage": "https://github.com/phanect/eslint-plugin-editorconfig",
"dependencies": {
"@typescript-eslint/eslint-plugin": "^5.0.0",
"editorconfig": "^0.15.0",
"eslint": "^8.0.1",
"klona": "^2.0.4"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint-config-phanective": "latest",
"mocha": "^9.1.3"
},
"engines": {
"node": ">=14",
"npm": ">=8"
}
}
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions test-packages/failure/missing-ts-eslint/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@phanect/test-package-ts",
"version": "1.0.0",
"description": "a test package",
"author": "Jumpei Ogawa <phanective@gmail.com>",
"license": "UNLICENSED",
"private": true,
"main": "main.js",
"scripts": {
"lint": "eslint . --ext=.js,.ts",
"test": "npm run lint"
},
"devDependencies": {
"@typescript-eslint/parser": "^5.0.0"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions test-packages/success/ts/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";

module.exports = {
root: true,
extends: "plugin:editorconfig/noconflict",

env: {
es6: true,
node: true,
},
parser: "@typescript-eslint/parser",
parserOptions: {
sourceType: "module",
},
plugins: [ "editorconfig" ],
rules: {
"editorconfig/charset": "error",
"editorconfig/eol-last": "error",
"editorconfig/indent": "error",
"editorconfig/linebreak-style": "error",
"editorconfig/no-trailing-spaces": "error",
},
};
5 changes: 5 additions & 0 deletions test-packages/success/ts/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

const bar: number = 0;

console.log(bar);
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"test": "npm run lint"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"typescript": "^4.1.3"
}
Expand Down
17 changes: 16 additions & 1 deletion test-packages/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,25 @@ git clean -Xd --force
cp --recursive "${TEST_PKGS_DIR}" "${TMP}/"

for ESLINT_VERSION in "7" "8"; do
for PKGDIR in $(find "${TMP}/test-packages/" -maxdepth 1 -type d ! -path "${TMP}/test-packages/"); do
for PKGDIR in $(find "${TMP}/test-packages/success/" -maxdepth 1 -type d ! -path "${TMP}/test-packages/success/"); do
cd "${PKGDIR}"
npm install
npm install --save-dev "eslint@${ESLINT_VERSION}" "${PROJECT_ROOT}/${PACKAGE}"
npm run lint
done

for PKGDIR in $(find "${TMP}/test-packages/failure/" -maxdepth 1 -type d ! -path "${TMP}/test-packages/failure/"); do
cd "${PKGDIR}"
npm install
npm install --save-dev "eslint@${ESLINT_VERSION}" "${PROJECT_ROOT}/${PACKAGE}"

if [[ "${PKGDIR}" = "${TMP}/test-packages/failure/missing-ts-eslint" ]]; then
if [[ -z "$((npm run lint 2>&1) | grep "eslint-plugin-editorconfig requires typescript and @typescript-eslint/eslint-plugin to lint \*.ts files. Run \`npm install typescript @typescript-eslint/eslint-plugin\`.")" ]]; then
echo "Error message is not shown properly when @typescript-eslint/eslint-plugin is missing" >&2
echo "ESLint's error message:"
npm run lint
exit 1
fi
fi
done
done

0 comments on commit 966f1cf

Please sign in to comment.