-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from phanect/cliengine-deprecation
Rule redesign & refactoring due to the CLIEngine deprecation
- Loading branch information
Showing
12 changed files
with
475 additions
and
407 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* @file Report and fix EditorConfig rule violation. | ||
* @author Jumpei Ogawa | ||
*/ | ||
"use strict"; | ||
|
||
const { rules } = require("@typescript-eslint/eslint-plugin"); | ||
const editorconfig = require("editorconfig"); | ||
const { Linter } = require("eslint"); | ||
const { klona } = require("klona/lite"); | ||
|
||
module.exports.buildRule = ({ baseRuleName, description, omitFirstOption, getESLintOption }) => { | ||
const jsBaseRule = new Linter().getRules().get(baseRuleName); | ||
const tsBaseRule = rules[baseRuleName] ? rules[baseRuleName] : jsBaseRule; | ||
|
||
// Remove first option | ||
if (omitFirstOption !== false) { | ||
jsBaseRule.meta.schema.shift(); | ||
} | ||
|
||
return { | ||
meta: { | ||
...jsBaseRule.meta, | ||
|
||
docs: { | ||
...jsBaseRule.meta.docs, | ||
description, | ||
url: "https://github.com/phanect/eslint-plugin-editorconfig", | ||
}, | ||
}, | ||
|
||
create: function(context) { | ||
const filename = context.getFilename(); | ||
const ecParams = editorconfig.parseSync(context.getFilename(filename)); | ||
const { enabled, eslintOption } = getESLintOption(ecParams); | ||
const baseRule = filename.endsWith(".ts") ? tsBaseRule : jsBaseRule; | ||
const _context = klona(context); | ||
|
||
if (eslintOption) { | ||
_context.options.unshift(eslintOption); | ||
} | ||
|
||
return enabled ? baseRule.create(_context) : {}; | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"use strict"; | ||
|
||
const { buildRule } = require("../base"); | ||
|
||
module.exports = buildRule({ | ||
baseRuleName: "unicode-bom", | ||
description: "Enforce EditorConfig rules for charset", | ||
getESLintOption: (ecParams) => { | ||
if (ecParams.charset === "utf-8") { | ||
return { enabled: true, eslintOption: "never" }; | ||
} else if (ecParams.charset === "utf-8-bom") { | ||
return { enabled: true, eslintOption: "always" }; | ||
} else { | ||
return { enabled: false }; | ||
} | ||
}, | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.