RFC: Custom eslint plugin (#3272)
* WIP * Renamed pacakge * Update yarn.lock * Lint fixes * Moved afterBufferTime to busyTimes & heavily simplify busy check (#3258) * New Crowdin translations by Github Action (#3312) Co-authored-by: Crowdin Bot <[email protected]> * Fix shell flicker (#3314) Co-authored-by: Peer Richelsen <[email protected]> * Add recommended config to plugin * Linting Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Crowdin Bot <[email protected]> Co-authored-by: Hariom Balhara <[email protected]>
This commit is contained in:
14 files changed
+404
-7
No files matched your search
@@ -20,8 +20,8 @@ module.exports = {
|
||||
overrides: [
|
||||
{
|
||||
files: ["*.ts", "*.tsx"],
|
||||
extends: ["plugin:@typescript-eslint/recommended"],
|
||||
plugins: ["@typescript-eslint"],
|
||||
extends: ["plugin:@typescript-eslint/recommended", "plugin:@calcom/eslint/recommended"],
|
||||
plugins: ["@typescript-eslint", "@calcom/eslint"],
|
||||
parser: "@typescript-eslint/parser",
|
||||
overrides: [
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"prettier-preset.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"@calcom/eslint-plugin-eslint": "*",
|
||||
"eslint-config-next": "^12.1.6",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-plugin-playwright": "^0.9.0",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable @calcom/eslint/deprecated-imports */
|
||||
import dayjs from "dayjs";
|
||||
import dayjsBusinessTime from "dayjs-business-days2";
|
||||
import customParseFormat from "dayjs/plugin/customParseFormat";
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "@calcom/eslint-plugin-eslint",
|
||||
"version": "0.1.0",
|
||||
"main": "./src/index.js",
|
||||
"dependencies": {
|
||||
"@typescript-eslint/parser": "^5.25.0",
|
||||
"@typescript-eslint/utils": "^5.30.5",
|
||||
"eslint": "^8.15.0",
|
||||
"ts-node": "^10.6.0",
|
||||
"typescript": "^4.6.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/eslint": "^8.4.5"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires, import/no-anonymous-default-export */
|
||||
export default {
|
||||
recommended: require("./recommended").default,
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
const recommended = {
|
||||
parser: "@typescript-eslint/parser",
|
||||
parserOptions: { sourceType: "module" },
|
||||
rules: {
|
||||
"@calcom/eslint/deprecated-imports": "error",
|
||||
},
|
||||
};
|
||||
|
||||
export default recommended;
|
||||
@@ -0,0 +1,11 @@
|
||||
// This registers Typescript compiler instance onto node.js.
|
||||
// Now it is possible to just require typescript files without any compilation steps in the environment run by node
|
||||
require("ts-node").register();
|
||||
|
||||
// re-export our rules so that eslint run by node can understand them
|
||||
module.exports = {
|
||||
// import our rules from the typescript file
|
||||
rules: require("./rules/index.ts").default,
|
||||
// import our config from the typescript file
|
||||
configs: require("./configs/index.ts").default,
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
import { ESLintUtils } from "@typescript-eslint/utils";
|
||||
|
||||
const createRule = ESLintUtils.RuleCreator((name) => `https://developer.cal.com/eslint/rule/${name}`);
|
||||
|
||||
const rule = createRule({
|
||||
create(context) {
|
||||
return {
|
||||
ImportDeclaration(node) {
|
||||
node.specifiers.length &&
|
||||
node.source.value === "dayjs" &&
|
||||
node.specifiers.forEach((item) => {
|
||||
if (item.local.name === "dayjs") {
|
||||
return context.report({
|
||||
node: item,
|
||||
loc: node.loc,
|
||||
messageId: "dayjs-moved",
|
||||
fix: (fixer) => fixer.replaceText(node, "import dayjs from '@calcom/dayjs'"),
|
||||
});
|
||||
}
|
||||
return null;
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
name: "deprecated-imports",
|
||||
meta: {
|
||||
fixable: "code",
|
||||
docs: {
|
||||
description: "Avoid deprecated imports",
|
||||
recommended: "warn",
|
||||
},
|
||||
messages: {
|
||||
"dayjs-moved": `Import dayjs from '@calcom/daysjs' to avoid plugin conflicts.`,
|
||||
},
|
||||
type: "suggestion",
|
||||
schema: [],
|
||||
},
|
||||
defaultOptions: [],
|
||||
});
|
||||
|
||||
export default rule;
|
||||
@@ -0,0 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires*/
|
||||
import type { ESLint } from "eslint";
|
||||
|
||||
export default {
|
||||
"my-first-rule": require("./my-first-rule").default,
|
||||
"deprecated-imports": require("./deprecated-imports").default,
|
||||
} as ESLint.Plugin["rules"];
|
||||
@@ -0,0 +1,23 @@
|
||||
import type { Rule } from "eslint";
|
||||
|
||||
const rule: Rule.RuleModule = {
|
||||
meta: {
|
||||
docs: {
|
||||
description: "This rule is run on typescript!",
|
||||
},
|
||||
},
|
||||
create: (context) => {
|
||||
return {
|
||||
VariableDeclarator: (node) => {
|
||||
if (node.id.type === "Identifier" && node.id.name !== "bla") {
|
||||
context.report({
|
||||
node,
|
||||
message: 'All variabled should be named "bla"!',
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default rule;
|
||||
Reference in new issue
Block a user