From 6f33eff760297c734559bf12d82e824050c22098 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Sun, 6 Sep 2020 11:11:46 -0700 Subject: [PATCH 1/2] Add check for broken links --- broken-links.txt | 95 +++++++++++++++++++++++++++++++++++++++ src/rules/dtHeaderRule.ts | 17 +++++++ 2 files changed, 112 insertions(+) create mode 100644 broken-links.txt diff --git a/broken-links.txt b/broken-links.txt new file mode 100644 index 00000000..ae04d1fc --- /dev/null +++ b/broken-links.txt @@ -0,0 +1,95 @@ +http://ace.ajax.org/ +http://adam.co/lab/jquery/customselect// +http://docs2x.smartfoxserver.com/api-docs/jsdoc/ +http://domo-js.com/ +http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobubble/src/ +http://hackedbychinese.github.io/ng-idle/ +http://jquery-watermark.googlecode.com +http://msdn.microsoft.com/en-us/library/ee341002(v=vs.100).aspx +http://msdn.microsoft.com/en-us/library/gg328255.aspx +http://msdn.microsoft.com/en-us/library/live/hh243643.aspx +http://msdn.microsoft.com/en-us/library/windows/apps/br211377.aspx +http://premiumsoftware.net/CLEditor +https://bitbucket.org/igor_sechyn/hystrixjs +https://cloud.google.com/monitoring/v2beta2/ +https://danielruf.github.io/html-minifier-terser/ +https://developer.pebble.com/docs/js/Pebble/ +https://developers.google.com/+/api/ +https://developers.google.com/+/domains/ +https://developers.google.com/games/services/web/api/states +https://developers.google.com/playmoviespartner/ +https://developers.google.com/url-shortener/ +https://developers.google.com/url-shortener/v1/getting_started +https://developers.google.com/+/web/people/ +https://docs.clearblade.com/v/3/4-developer_reference/platformsdk/ClearBlade.js/ +https://fleury.io/vanilla-masker/ +https://github.com/absinthe-graphql/absinthe-socket/tree/master/packages/absinthe-phoenix-socket-apollo-link#readme +https://github.com/ampproject/amphtml/tree/master/validator/nodejs +https://github.com/apollostack/optics-agent-js#readme +https://github.com/baz/foo +https://github.com/Beng89/node-array-ext +https://github.com/codetheorist/three-tds-loader +https://github.com/darkskyapp/tz-lookup#readme +https://github.com/darrenthill/jsuite +https://github.com/dropbox/dropbox-js +https://github.com/Ebongarde/ebongarde-root#readme +https://github.com/ehynds/jquery-notify (jQuery Notify UI Widget by Eric Hynds) +https://github.com/formidablelabs/enzyme-matchers/packages/jasmine-enzyme +https://github.com/godaddy/short-css-vars/packages/short-css-vars#readme +https://github.com/google/google-protobuf +https://github.com/herobank110/types-d3-indirections +https://github.com/jbaldwin/gridster +https://github.com/jonathanepollack/gulp-minify-css +https://github.com/LeTools/LeState +https://github.com/madglory/backbone-fetch-cache +https://github.com/murphydanger/gulp-minify-html +https://github.com/nodets/node-mysql-wrapper +https://github.com/nodets/socket.io.users +https://github.com/parcel/parcel-bundler +https://github.com/roryrjb/easydate +https://github.com/satoshilabs/invity-api (not public repo) +https://github.com/s-barrah/url-slugify#readme +https://github.com/sonaye/mobx-apollo#readme +https://github.com/storybookjs/storybook/tree/master/addons/info +https://github.com/storybookjs/storybook/tree/master/app/polymer +https://github.com/text-mask/text-mask/core/#readme +https://github.com/Wirewheel/connect-history-api-fallback#readme +https://github.com/xDae/react-plyr +https://github.com/zalando-incubator/solution-center-communicator +https://github.com/zippyui/react-flex +https://github.elenet.me/fe/obsolete-webpack-plugin +https://github.hubspot.com/shepherd/ +https://gitlab.baidu.com/fex/node-ral +https://mlkcca.com/ +https://msdn.microsoft.com/en-us/library/9bbdkx3k.aspx +https://msdn.microsoft.com/en-us/library/aa741317(v=vs.85).aspx +https://msdn.microsoft.com/en-us/library/aa752040(v=vs.85).aspx +https://msdn.microsoft.com/en-us/library/bstcxhf7(v=vs.84).aspx +https://msdn.microsoft.com/en-us/library/dn124645.aspx +https://msdn.microsoft.com/en-us/library/dn142571.aspx +https://msdn.microsoft.com/en-us/library/ff521046(v=vs.85).aspx +https://msdn.microsoft.com/en-us/library/fp161225.aspx +https://msdn.microsoft.com/en-us/library/fp179694.aspx +https://msdn.microsoft.com/en-us/library/fp179696.aspx +https://msdn.microsoft.com/en-us/library/hh272953.aspx +https://msdn.microsoft.com/en-us/library/jj249010.aspx +https://msdn.microsoft.com/en-us/library/jj602751.aspx +https://msdn.microsoft.com/en-us/library/ms763742.aspx +https://msdn.microsoft.com/en-us/library/office/jj193034.aspx +https://msdn.microsoft.com/en-us/library/windows/desktop/bb773938(v=vs.85).aspx +https://msdn.microsoft.com/en-us/library/windows/desktop/ms630368(v=vs.85).aspx +https://msdn.microsoft.com/en-us/library/windows/desktop/ms684513(v=vs.85).aspx +https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/collections-visual-basic-add-in-model +https://msdn.microsoft.com/en-us/vba/vba-outlook +https://msdn.microsoft.com/VBA/Language-Reference-VBA/articles/reference-microsoft-forms +https://msdn.microsoft.com/VBA/Office-Shared-VBA/articles/office-vba-object-library-reference +https://react-countup.now.sh +https://yarnpkg.github.io/berry/advanced/pnpapi +http://welldonethings.com/tags/manager +http://www.prismtech.com/vortex/vortex-web +http://www.ui-grid.info/ +http://www.whoop.ee/posts/2013-04-05-the-resurrection-of-jquery-notify-bar/ +- (link to the repo is missing) +meteor-universe-i18n +sic-ecies +undefined diff --git a/src/rules/dtHeaderRule.ts b/src/rules/dtHeaderRule.ts index 82d306ee..1ad92baa 100644 --- a/src/rules/dtHeaderRule.ts +++ b/src/rules/dtHeaderRule.ts @@ -1,4 +1,7 @@ import { renderExpected, validate } from "@definitelytyped/header-parser"; +import * as cp from "child_process"; +import { dtToNpmName, findDtsName } from "dts-critic"; +import { readFileSync } from "fs"; import * as Lint from "tslint"; import * as ts from "typescript"; import { failure, isMainFile } from "../util"; @@ -34,6 +37,20 @@ function walk(ctx: Lint.WalkContext): void { return; } + let message = "This link seems to be broken. There was an error trying to visit it."; + const name = findDtsName(sourceFile.fileName); + const npmName = dtToNpmName(name); + const { stdout } = cp.spawnSync("npm", ["view", npmName, "homepage"], { encoding: "utf8" }); + const [homepage] = stdout.split(/\r?\n/, 1); + if (homepage) { + message += ` Did you mean ${homepage}?`; + } + for (const brokenLink of readFileSync("broken-links.txt", "utf8").split(/\r?\n/)) { + if (brokenLink) { + lookFor(brokenLink, message); + } + } + lookFor("// Definitions by: My Self", "Author name should be your name, not the default."); const error = validate(text); if (error) { From f8c0336aba5098b0ecbe993afa32218fc049c7db Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Sun, 6 Sep 2020 11:14:48 -0700 Subject: [PATCH 2/2] Add tests --- test/dt-header/wrong/types/broken-link/index.d.ts.lint | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 test/dt-header/wrong/types/broken-link/index.d.ts.lint diff --git a/test/dt-header/wrong/types/broken-link/index.d.ts.lint b/test/dt-header/wrong/types/broken-link/index.d.ts.lint new file mode 100644 index 00000000..ad373ac7 --- /dev/null +++ b/test/dt-header/wrong/types/broken-link/index.d.ts.lint @@ -0,0 +1,5 @@ +// Type definitions for dt-header 1.0 +// Project: http://ace.ajax.org/ + ~~~~~~~~~~~~~~~~~~~~ [This link seems to be broken. There was an error trying to visit it. Did you mean https://github.com/rafaelrinaldi/broken-link#readme? See: https://github.com/Microsoft/dtslint/blob/master/docs/dt-header.md] +// Definitions by: Jane Doe +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped