Skip to content

Commit

Permalink
fix short url (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
gucong3000 committed Apr 9, 2018
1 parent 9ba44de commit 7d32f76
Show file tree
Hide file tree
Showing 13 changed files with 2,351 additions and 2,270 deletions.
9 changes: 3 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ jobs:
- run:
name: Creating Artifacts
command: |
npm run -s shorturl
mkdir -p /tmp/json_artifacts/lib
cp package.json /tmp/json_artifacts
cp lib/*.json /tmp/json_artifacts/lib
npm run -s shorturl || (mkdir -p /tmp/short_urls/lib && cp lib/*.json /tmp/short_urls/lib)
when: always
- store_artifacts:
path: /tmp/json_artifacts
destination: short url
path: /tmp/short_urls
destination: short URLs
- store_test_results:
path: ~/lint-reports
7 changes: 1 addition & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{
"parserOptions": {
"sourceType": "script",
"impliedStrict": false
},
"env": {
"es6": true,
"node": true
"sourceType": "script"
},
"extends": [
"standard"
Expand Down
5 changes: 1 addition & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,4 @@ test_script:
# to run your custom scripts instead of provider deployments
after_test:
- npm run report-coverage
- npm run -s shorturl
- git diff --name-only > git_diff.log || echo ""
- git diff --cached --name-only >> git_diff.log || echo ""
- test ! -s git_diff.log || 7z a shorturl.zip @git_diff.log && appveyor PushArtifact shorturl.zip
- npm run -s shorturl || (7z a shorturl.zip lib/*.json && appveyor PushArtifact shorturl.zip)
37 changes: 17 additions & 20 deletions lib/eslint-error.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
'use strict';
const LintError = require('./lint-error');
const locale = require('./locale');

const npmUrlPrefix = 'https://www.npmjs.com/package/eslint-plugin-';
const pluginDocBaseUrl = {
flowtype: 'https://www.npmjs.com/package/eslint-plugin-flowtype#',
gettext: 'https://www.npmjs.com/package/eslint-plugin-gettext#',
promise: 'https://www.npmjs.com/package/eslint-plugin-promise#',
alint: 'https://www.npmjs.com/package/eslint-plugin-alint#',
jsdoc: 'https://www.npmjs.com/package/eslint-plugin-jsdoc#',
sql: 'https://www.npmjs.com/package/eslint-plugin-sql#',
standard: 'https://www.npmjs.com/package/eslint-plugin-standard#rules-explanations',
sql: rule => npmUrlPrefix + `sql#eslint-plugin-sql-rules-${rule}`,
standard: () => npmUrlPrefix + 'standard#rules-explanations',
gettext: rule => npmUrlPrefix + `gettext#gettext${rule}`,
compat: (rule, error) => (
rule === 'compat' && error.message.replace(
/^(?:[a-z]+\.)?(\w+).*$/,
Expand All @@ -19,6 +15,13 @@ const pluginDocBaseUrl = {
)
),
};
[
'flowtype',
'jsdoc',
'alint',
].forEach((plugin) => {
pluginDocBaseUrl[plugin] = rule => npmUrlPrefix + plugin + '#' + rule;
});

/**
* ESLint错误对象
Expand Down Expand Up @@ -93,24 +96,18 @@ function docUrl (rule, error) {
if (!rule) {
return;
}
let plugin;
let baseUrl;
if (/^(.+?)\/(.+)$/.test(rule)) {
plugin = RegExp.$1;
rule = RegExp.$2;
baseUrl = lookupPluginDocBaseUrl(RegExp.$1);
baseUrl = lookupPluginDocBaseUrl(plugin);
if (baseUrl) {
return baseUrl(rule, error);
}
} else {
return `https://${locale === 'zh_CN' ? 'cn.' : ''}eslint.org/docs/rules/${rule}`;
}
if (baseUrl) {
if (typeof baseUrl === 'function') {
try {
return baseUrl(rule, error);
} catch (ex) {
//
}
} else {
return baseUrl.replace(/(#)$/, '$1' + rule);
}
}
}

module.exports = ESLintError;
10 changes: 5 additions & 5 deletions lib/short-doc-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ function shortDocUrl (error) {
if (!error.doc) {
return error;
}
return shortUrl(error.doc).then(shortUrl => {
return shortUrl(error.doc).catch(ex => {
//
}).then(shortUrl => {
if (shortUrl) {
error.docShort = shortUrl;
}
return error;
}, () => {
return error;
});
}

Expand All @@ -36,10 +36,10 @@ function shortUrl (url) {
}
return isInGFW.then(inGFW => {
if (inGFW) {
return got(`http://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long=${encodeURIComponent(url)}`, {
return got(`https://api.t.sina.com.cn/short_url/shorten.json?source=3271760578&url_long=${encodeURIComponent(url)}`, {
json: true,
}).then(result => {
return result.body[0].url_short;
return result.body[0].url_short.replace(/^https?/i, 'https');
});
} else {
return googl.shorten(url);
Expand Down
25 changes: 4 additions & 21 deletions lib/shorturl.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,6 @@
"http://jscs.info/rule/validateorderinobjectkeys": "https://goo.gl/awRGmF",
"http://jscs.info/rule/validateparameterseparator": "https://goo.gl/fsC3cQ",
"http://jscs.info/rule/validatequotemarks": "https://goo.gl/ANKpFh",
"http://jscs.info/rules#disallowspacesinanonymousfunctionexpression": "https://goo.gl/SqL8gU",
"http://jscs.info/rules#disallowspacesinnamedfunctionexpression": "https://goo.gl/nkKUhJ",
"http://jscs.info/rules#requirespacesinanonymousfunctionexpression": "https://goo.gl/estety",
"http://jscs.info/rules#requirespacesinnamedfunctionexpression": "https://goo.gl/D09Mlf",
"https://cn.eslint.org/docs/rules/accessor-pairs": "https://goo.gl/zNSKkQ",
"https://cn.eslint.org/docs/rules/array-bracket-newline": "https://goo.gl/W36GJw",
"https://cn.eslint.org/docs/rules/array-bracket-spacing": "https://goo.gl/224A3t",
Expand Down Expand Up @@ -1285,6 +1281,7 @@
"https://github.com/lukeapage/eslint-plugin-switch-case/blob/head/docs/rules/newline-between-switch-case.md#readme": "https://goo.gl/gZ2giY",
"https://github.com/lukeapage/eslint-plugin-switch-case/blob/head/docs/rules/no-case-curly.md#readme": "https://goo.gl/NJYBGw",
"https://github.com/ma27/eslint-plugin-varspacing/blob/head/docs/rules/var-spacing.md#readme": "https://goo.gl/qzgjrA",
"https://github.com/maikziemer/eslint-plugin-extras/blob/head/docs/rules/sort-named-imports.md#readme": "https://goo.gl/acJG2H",
"https://github.com/manovotny/eslint-plugin-get-off-my-lawn/blob/head/docs/rules/prefer-arrow-functions.md#readme": "https://goo.gl/fJXthJ",
"https://github.com/meetup/eslint-plugin-meetup/blob/head/docs/rules/trn.md#readme": "https://goo.gl/1cX4Nc",
"https://github.com/mysticatea/eslint-plugin-es/blob/head/docs/rules/no-accessor-properties.md#readme": "https://goo.gl/dbL4ug",
Expand Down Expand Up @@ -2129,7 +2126,7 @@
"https://www.npmjs.com/package/eslint-plugin-flowtype#union-intersection-spacing": "https://goo.gl/ePu9XR",
"https://www.npmjs.com/package/eslint-plugin-flowtype#use-flow-type": "https://goo.gl/VJzAUP",
"https://www.npmjs.com/package/eslint-plugin-flowtype#valid-syntax": "https://goo.gl/cV5CgF",
"https://www.npmjs.com/package/eslint-plugin-gettext#no-variable-string": "https://goo.gl/wTkD6A",
"https://www.npmjs.com/package/eslint-plugin-gettext#gettextno-variable-string": "https://goo.gl/GV1cwe",
"https://www.npmjs.com/package/eslint-plugin-i18n-json#identical-keys": "https://goo.gl/r49Mkv",
"https://www.npmjs.com/package/eslint-plugin-i18n-json#valid-json": "https://goo.gl/6W6Uyi",
"https://www.npmjs.com/package/eslint-plugin-i18n-json#valid-message-syntax": "https://goo.gl/6HQ9ey",
Expand Down Expand Up @@ -2163,21 +2160,7 @@
"https://www.npmjs.com/package/eslint-plugin-mongodb#check-unset-updates": "https://goo.gl/ins9BT",
"https://www.npmjs.com/package/eslint-plugin-mongodb#check-update-calls": "https://goo.gl/ULmdkT",
"https://www.npmjs.com/package/eslint-plugin-mongodb#no-replace": "https://goo.gl/UQH7fL",
"https://www.npmjs.com/package/eslint-plugin-promise#always-return": "https://goo.gl/qbHFxN",
"https://www.npmjs.com/package/eslint-plugin-promise#avoid-new": "https://goo.gl/kfHjjH",
"https://www.npmjs.com/package/eslint-plugin-promise#catch-or-return": "https://goo.gl/GiDuvA",
"https://www.npmjs.com/package/eslint-plugin-promise#no-callback-in-promise": "https://goo.gl/J3TRcg",
"https://www.npmjs.com/package/eslint-plugin-promise#no-native": "https://goo.gl/vHDcv1",
"https://www.npmjs.com/package/eslint-plugin-promise#no-nesting": "https://goo.gl/oKJtLn",
"https://www.npmjs.com/package/eslint-plugin-promise#no-new-statics": "https://goo.gl/3vuREY",
"https://www.npmjs.com/package/eslint-plugin-promise#no-promise-in-callback": "https://goo.gl/urdqq6",
"https://www.npmjs.com/package/eslint-plugin-promise#no-return-in-finally": "https://goo.gl/Cz1CoJ",
"https://www.npmjs.com/package/eslint-plugin-promise#no-return-wrap": "https://goo.gl/ZPggpp",
"https://www.npmjs.com/package/eslint-plugin-promise#param-names": "https://goo.gl/u2GzNs",
"https://www.npmjs.com/package/eslint-plugin-promise#prefer-await-to-callbacks": "https://goo.gl/JRvLMY",
"https://www.npmjs.com/package/eslint-plugin-promise#prefer-await-to-then": "https://goo.gl/Gmi9Bn",
"https://www.npmjs.com/package/eslint-plugin-promise#valid-params": "https://goo.gl/iAcfZH",
"https://www.npmjs.com/package/eslint-plugin-sql#format": "https://goo.gl/pB6NtD",
"https://www.npmjs.com/package/eslint-plugin-sql#no-unsafe-query": "https://goo.gl/ahUcDH",
"https://www.npmjs.com/package/eslint-plugin-sql#eslint-plugin-sql-rules-format": "https://goo.gl/QHF2Ft",
"https://www.npmjs.com/package/eslint-plugin-sql#eslint-plugin-sql-rules-no-unsafe-query": "https://goo.gl/aErVi6",
"https://www.npmjs.com/package/eslint-plugin-standard#rules-explanations": "https://goo.gl/sqb2hd"
}
Loading

0 comments on commit 7d32f76

Please sign in to comment.