Skip to content

Commit

Permalink
fix: update recommended config
Browse files Browse the repository at this point in the history
  • Loading branch information
zengxiaoluan committed Aug 9, 2024
1 parent 23bb909 commit a81a322
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 17 deletions.
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,25 @@ Then configure the rules you want to use under the rules section.

<!-- begin auto-generated configs list -->

TODO: Run eslint-doc-generator to generate the configs list (or delete this section if no configs are offered).
| | Name |
| :- | :------------ |
|| `recommended` |

<!-- end auto-generated configs list -->

## Rules

<!-- begin auto-generated rules list -->

| Name | Description |
| :--------------------------------------------------------------- | :-------------------------------------------- |
| [always-camel-case](docs/rules/always-camel-case.md) | Always camel case every thing |
| [comments-need-space](docs/rules/comments-need-space.md) | comments need space |
| [kebab-case](docs/rules/kebab-case.md) | kebab case your file name and directory name. |
| [no-then](docs/rules/no-then.md) | No then with promise |
| [prefer-template-literal](docs/rules/prefer-template-literal.md) | prefer template literal |
💼 Configurations enabled in.\
✅ Set in the `recommended` configuration.

| Name | Description | 💼 |
| :--------------------------------------------------------------- | :-------------------------------------------- | :- |
| [always-camel-case](docs/rules/always-camel-case.md) | Always camel case every thing ||
| [comments-need-space](docs/rules/comments-need-space.md) | comments need space ||
| [kebab-case](docs/rules/kebab-case.md) | kebab case your file name and directory name. ||
| [no-then](docs/rules/no-then.md) | No then with promise ||
| [prefer-template-literal](docs/rules/prefer-template-literal.md) | prefer template literal ||

<!-- end auto-generated rules list -->
2 changes: 2 additions & 0 deletions docs/rules/always-camel-case.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Always camel case every thing (`jlc/always-camel-case`)

💼 This rule is enabled in the ✅ `recommended` config.

<!-- end auto-generated rule header -->

## Rule Details
Expand Down
2 changes: 2 additions & 0 deletions docs/rules/comments-need-space.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Comments need space (`jlc/comments-need-space`)

💼 This rule is enabled in the ✅ `recommended` config.

<!-- end auto-generated rule header -->

Comments like below is not ok:
Expand Down
2 changes: 2 additions & 0 deletions docs/rules/kebab-case.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Kebab case your file name and directory name (`jlc/kebab-case`)

💼 This rule is enabled in the ✅ `recommended` config.

<!-- end auto-generated rule header -->

If you naming filename like this, it's bad case:
Expand Down
2 changes: 2 additions & 0 deletions docs/rules/no-then.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# No then with promise (`jlc/no-then`)

💼 This rule is enabled in the ✅ `recommended` config.

<!-- end auto-generated rule header -->

That is bad:
Expand Down
2 changes: 2 additions & 0 deletions docs/rules/prefer-template-literal.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Prefer template literal (`jlc/prefer-template-literal`)

💼 This rule is enabled in the ✅ `recommended` config.

<!-- end auto-generated rule header -->

That is bad:
Expand Down
15 changes: 15 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@ import pluginJs from "@eslint/js";
import pluginNode from "eslint-plugin-n";
import eslintPlugin from "eslint-plugin-eslint-plugin";

import * as jlc from "./lib/index.js";

export default [
pluginJs.configs.recommended,
...pluginNode.configs["flat/mixed-esm-and-cjs"],
eslintPlugin.configs["flat/recommended"],

{
files: ["**/*.js"],
languageOptions: {
sourceType: "commonjs",
ecmaVersion: "latest",
},
// Using the eslint-plugin-example plugin defined locally
plugins: { jlc },
rules: {
"jlc/kebab-case": "error",
},
},
];
5 changes: 5 additions & 0 deletions lib/configs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

module.exports = {
recommended: require("./configs/recommended"),
};
10 changes: 10 additions & 0 deletions lib/configs/recommended.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
plugins: ["jlc"],
rules: {
"jlc/always-camel-case": "error",
"jlc/comments-need-space": "error",
"jlc/kebab-case": "error",
"jlc/no-then": "error",
"jlc/prefer-template-literal": "error",
},
};
8 changes: 3 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @fileoverview Preferences eslint rule for zeng
* @author eslint-plugin-zeng
* @fileoverview An opinionated collection of ESLint rules used by JLC.
* @author zengxiaoluan
*/
"use strict";

Expand All @@ -14,9 +14,7 @@ const requireIndex = require("requireindex");
// Plugin Definition
//------------------------------------------------------------------------------


// import all rules in lib/rules
module.exports.rules = requireIndex(__dirname + "/rules");



module.exports.configs = requireIndex(__dirname + "/configs");
9 changes: 7 additions & 2 deletions lib/rules/kebab-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
// Rule Definition
//------------------------------------------------------------------------------

let { url, parseFilename } = require("../utils");

/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: `problem`, // `problem`, `suggestion`, or `layout`
docs: {
description: "kebab case your file name and directory name.",
recommended: false,
url: require("../utils").url(module), // URL to the documentation page for this rule
url: url(module), // URL to the documentation page for this rule
},
fixable: null, // Or `code` or `whitespace`
schema: [], // Add a schema if the rule has options
Expand Down Expand Up @@ -43,8 +45,11 @@ module.exports = {
return {
Program: function (node) {
let filename = context.filename;
let physicalFilename = context.physicalFilename;

let parsed = parseFilename(physicalFilename);

let matchesRegex = conventionRegexp.test(filename);
let matchesRegex = conventionRegexp.test(parsed.base);

if (matchesRegex) {
context.report({
Expand Down
12 changes: 12 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ function url({ id }) {
return url.toString();
}

function parseFilename(filename) {
let ext = path.extname(filename);

return {
dir: path.dirname(filename),
base: path.basename(filename),
ext: ext,
name: path.basename(filename, ext),
};
}

module.exports = {
url,
parseFilename,
};
4 changes: 2 additions & 2 deletions package-lock.json

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

0 comments on commit a81a322

Please sign in to comment.