Skip to content
Open
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
11 changes: 11 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ module.exports = {
},
ignorePatterns: [ "test-packages/**" ],
rules: {
"node/no-unpublished-import": "off",
"node/no-unpublished-require": "off",
"node/no-unsupported-features/es-syntax": "off",
},
overrides: [
{
files: [ "examples/flat-config/**/*" ],
parserOptions: {
sourceType: "module",
project: "./examples/flat-config/tsconfig.json",
},
},
],
};
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ An ESLint plugin to enforce EditorConfig rules
$ npm install --save-dev eslint@8 eslint-plugin-editorconfig
```

or

```bash
$ yarn add --dev eslint@8 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
Expand Down Expand Up @@ -78,11 +72,7 @@ It is recommended to disable them.
- `linebreak-style`
- `no-trailing-spaces`
- `unicode-bom`
- `@typescript-eslint/eol-last`
- `@typescript-eslint/indent`
- `@typescript-eslint/linebreak-style`
- `@typescript-eslint/no-trailing-spaces`
- `@typescript-eslint/unicode-bom`

If above rules are specified in your .eslintrc, just remove them.
If they are specified in the extended config, consider adding `plugin:editorconfig/noconflict` to your `extends`.
Expand Down
2 changes: 1 addition & 1 deletion examples/flat-config/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export default [
plugins: [ "editorconfig" ],
}).map(config => ({
...config,
ignores: [ join(__dirname, "src/invalid.ts") ]
ignores: [ join(__dirname, "src/invalid.ts") ],
})),
];
8 changes: 6 additions & 2 deletions examples/flat-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
"scripts": {
"lint": "eslint ."
},
"dependencies": {
"undici": "^6.2.1"
},
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@phanect/configs": "latest",
"@types/node": "^20.10.6",
"eslint": "^8.56.0",
"eslint-plugin-editorconfig": "^4.0.3",
"undici": "^6.2.1"
"eslint-plugin-editorconfig": "^4.0.3"
}
}
1 change: 1 addition & 0 deletions examples/flat-config/src/invalid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { fetch } from "undici";
const res = await fetch("https://example.com");

try {
// eslint-disable-next-line editorconfig/indent
const data = await res.json(); // This line should be warned by this plugin
console.log(data);
} catch (err) {
Expand Down
4 changes: 4 additions & 0 deletions examples/flat-config/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "@phanect/configs/tsconfig/nodejs",
"include": [ "**/*.ts" ]
}
7 changes: 3 additions & 4 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ module.exports.buildRule = ({ baseRuleName, description, omitFirstOption, getESL
},

create: function(context) {
const filename = context.getFilename();
const ecParams = editorconfig.parseSync(context.getFilename(filename));
const ecParams = editorconfig.parseSync(context.filename);
const { enabled, eslintOption } = getESLintOption(ecParams);

let baseRule;

if (filename.endsWith(".ts")) {
if (context.filename.endsWith(".ts")) {
try {
const { rules } = require("@typescript-eslint/eslint-plugin");
baseRule = rules[baseRuleName] ? klona(rules[baseRuleName]) : jsBaseRule;
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`.");
Expand Down
8 changes: 0 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ module.exports = {
"linebreak-style": "off",
"no-trailing-spaces": "off",
"unicode-bom": "off",
"@typescript-eslint/eol-last": "off",
"@typescript-eslint/indent": "off",
"@typescript-eslint/linebreak-style": "off",
"@typescript-eslint/no-trailing-spaces": "off",
"@typescript-eslint/unicode-bom": "off",
},
},
all: {
Expand All @@ -30,11 +26,7 @@ module.exports = {
"linebreak-style": "off",
"no-trailing-spaces": "off",
"unicode-bom": "off",
"@typescript-eslint/eol-last": "off",
"@typescript-eslint/indent": "off",
"@typescript-eslint/linebreak-style": "off",
"@typescript-eslint/no-trailing-spaces": "off",
"@typescript-eslint/unicode-bom": "off",

"editorconfig/charset": "error",
"editorconfig/eol-last": "error",
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"url": "https://github.com/phanect/eslint-plugin-editorconfig/issues"
},
"homepage": "https://github.com/phanect/eslint-plugin-editorconfig",
"workspaces": [
"examples/*"
],
"dependencies": {
"editorconfig": "^1.0.2",
"eslint": "^8.40.0",
Expand Down
12 changes: 12 additions & 0 deletions test-packages/success/base-rules-conflict/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
12 changes: 12 additions & 0 deletions test-packages/success/js/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
12 changes: 12 additions & 0 deletions test-packages/success/ts/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
9 changes: 0 additions & 9 deletions tests/lib/rules/editorconfig-ts.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
"use strict";

// -----------------------------------------------------------------------------
// Requirements
// -----------------------------------------------------------------------------

const path = require("path");
const RuleTester = require("eslint").RuleTester;


// -----------------------------------------------------------------------------
// Tests
// -----------------------------------------------------------------------------

const ruleTester = new RuleTester({
parser: require.resolve("@typescript-eslint/parser"),
parserOptions: {
Expand Down
9 changes: 0 additions & 9 deletions tests/lib/rules/editorconfig.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
"use strict";

// -----------------------------------------------------------------------------
// Requirements
// -----------------------------------------------------------------------------

const path = require("path");
const RuleTester = require("eslint").RuleTester;


// -----------------------------------------------------------------------------
// Tests
// -----------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2019 }});

const commonValidTests = [
Expand Down