Skip to content

Commit

Permalink
fix(rule-metadata): fixed issue with generation of manual url with co…
Browse files Browse the repository at this point in the history
…debase use of version

Preventative measure to ensure URLs are managed better in case version entries change. This was
primarily noticed due to the webpack build of the url generated with 0.0.0-semantically-versioned
entry was now in the url during testing, weird case but not caught. This change intends to make it
more realistic but it will still be v0.0.0 otherwise default to master.
  • Loading branch information
codejedi365 committed Nov 6, 2021
1 parent ae9997e commit 3b71e8c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/create-rule.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { parse as parsePath } from "path";
import { ESLintUtils } from "@typescript-eslint/experimental-utils";
import { repository, version } from "../package.json";
import semverCoerce from "semver/functions/coerce";
import thisPkg from "../package.json";

const REPO_URL = repository.url
const pkgVersion = semverCoerce(thisPkg.version)?.version;
const REPO_URL = thisPkg.repository.url
.replace(/git:\/\//, "https://")
.replace(/\.git$/, "");

export const createRule = ESLintUtils.RuleCreator((name) => {
const ruleName = parsePath(name).name;
return `${REPO_URL}/blob/v${version}/docs/rules/${ruleName}.md`;
const tag = !pkgVersion ? "master" : `v${pkgVersion}`;
return `${REPO_URL}/blob/${tag}/docs/rules/${ruleName}.md`;
});
export default createRule;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
"remark-preset-prettier": "^0.5.1",
"resolve-from": "^5.0.0",
"semantic-release": "^18.0.0",
"semver": "^7.3.5",
"ts-jest": "^27.0.5",
"ts-loader": "^9.2.6",
"ts-node": "^10.2.1",
Expand All @@ -91,7 +90,8 @@
"webpack-node-externals": "^3.0.0"
},
"dependencies": {
"@typescript-eslint/experimental-utils": "^5.2.0"
"@typescript-eslint/experimental-utils": "^5.2.0",
"semver": "^7.3.5"
},
"peerDependencies": {
"eslint": "^7.0.0 || ^8.0.0"
Expand Down

0 comments on commit 3b71e8c

Please sign in to comment.