Chore: MEGA - Make Eslint Great Again 💅 (#26094)

* Fix lint error in types.ts

* Bump eslint and its deps to latest

* Add eslintignore and remove not needed eslintrcs

* Change webpack configs eslint config

* Update package.jsons and removed unused eslintrc files

* Chore yarn lint --fix 💅

* Add devenv to eslintignore

* Remove eslint disable comments for rules that are not used

* Remaining eslint fixes 💅

* Bump grafana/eslint-config 💥

* Modify package.json

No need for duplicate checks.

* Modify eslintignore to ignore data and dist folders

* Revert removing .eslintrc to make sure not to use certain packages

* Modify package.json to remove not needed command

* Use gitignore for ignoring paths
This commit is contained in:
Zoltán Bedi
2020-08-11 17:52:44 +02:00
committed by GitHub
parent e4da0fcb5e
commit ae30482465
94 changed files with 873 additions and 892 deletions
+10 -3
View File
@@ -1,6 +1,13 @@
{
"extends": ["@grafana/eslint-config"],
"rules": {
"no-restricted-imports": [2, "^@grafana/data.*", "^@grafana/runtime.*", "^@grafana/ui.*"]
}
"no-restricted-imports": ["error", { "patterns": ["@grafana/runtime", "@grafana/ui", "@grafana/data"] }]
},
"overrides": [
{
"files": ["**/*.test.{ts,tsx}"],
"rules": {
"no-restricted-imports": "off"
}
}
]
}
+1 -1
View File
@@ -1,4 +1,4 @@
'use strict'
'use strict';
if (process.env.NODE_ENV === 'production') {
module.exports = require('./index.production.js');
-2
View File
@@ -19,7 +19,6 @@
"bundle": "rollup -c rollup.config.ts",
"clean": "rimraf ./dist ./compiled",
"docsExtract": "mkdir -p ../../reports/docs && api-extractor run 2>&1 | tee ../../reports/docs/$(basename $(pwd)).log",
"lint": "eslint src/ --ext=.js,.ts,.tsx",
"typecheck": "tsc --noEmit"
},
"dependencies": {
@@ -30,7 +29,6 @@
"xss": "1.0.6"
},
"devDependencies": {
"@grafana/eslint-config": "^1.0.0-rc1",
"@grafana/tsconfig": "^1.0.0-rc1",
"@rollup/plugin-commonjs": "11.0.2",
"@rollup/plugin-json": "4.0.3",
@@ -21,7 +21,6 @@
"bundle": "rollup -c rollup.config.ts",
"clean": "rimraf ./dist ./compiled",
"docsExtract": "mkdir -p ../../reports/docs && api-extractor run 2>&1 | tee ../../reports/docs/$(basename $(pwd)).log",
"lint": "eslint src/ --ext=.js,.ts,.tsx",
"typecheck": "tsc --noEmit"
},
"devDependencies": {
-1
View File
@@ -24,7 +24,6 @@
"bundle": "rollup -c rollup.config.ts",
"clean": "rimraf ./dist ./compiled",
"docsExtract": "mkdir -p ../../reports/docs && api-extractor run 2>&1 | tee ../../reports/docs/$(basename $(pwd)).log",
"lint": "eslint cypress/ src/ --ext=.js,.ts,.tsx",
"open": "cypress open",
"start": "cypress run --headless --browser chrome",
"test": "pushd test && node ../dist/bin/grafana-e2e.js run",
+1 -2
View File
@@ -1,6 +1,5 @@
{
"extends": ["@grafana/eslint-config"],
"rules": {
"no-restricted-imports": [2, "^@grafana/runtime.*"]
"no-restricted-imports": ["error", { "patterns": ["@grafana/runtime"] }]
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
'use strict'
'use strict';
if (process.env.NODE_ENV === 'production') {
module.exports = require('./index.production.js');
-1
View File
@@ -19,7 +19,6 @@
"bundle": "rollup -c rollup.config.ts",
"clean": "rimraf ./dist ./compiled",
"docsExtract": "mkdir -p ../../reports/docs && api-extractor run 2>&1 | tee ../../reports/docs/$(basename $(pwd)).log",
"lint": "eslint src/ --ext=.js,.ts,.tsx",
"typecheck": "tsc --noEmit"
},
"dependencies": {
+1 -2
View File
@@ -1,6 +1,5 @@
{
"extends": ["@grafana/eslint-config"],
"rules": {
"no-restricted-imports": [2, "^@grafana/runtime.*"]
"no-restricted-imports": ["error", { "patterns": ["@grafana/runtime"] }]
}
}
@@ -1,121 +1,153 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var getPluginId_1 = require("../../config/utils/getPluginId");
var pluginValidation_1 = require("../../config/utils/pluginValidation");
var env_1 = require("../../plugins/env");
var path = require("path");
var fs = require("fs");
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var tslib_1 = require('tslib');
var getPluginId_1 = require('../../config/utils/getPluginId');
var pluginValidation_1 = require('../../config/utils/pluginValidation');
var env_1 = require('../../plugins/env');
var path = require('path');
var fs = require('fs');
// @ts-ignore
// import execa = require('execa');
var githubClient_1 = tslib_1.__importDefault(require("./githubClient"));
var resolveContentType = function (extension) {
if (extension.startsWith('.')) {
extension = extension.substr(1);
}
switch (extension) {
case 'zip':
return 'application/zip';
case 'json':
return 'application/json';
case 'sha1':
return 'text/plain';
default:
return 'application/octet-stream';
}
var githubClient_1 = tslib_1.__importDefault(require('./githubClient'));
var resolveContentType = function(extension) {
if (extension.startsWith('.')) {
extension = extension.substr(1);
}
switch (extension) {
case 'zip':
return 'application/zip';
case 'json':
return 'application/json';
case 'sha1':
return 'text/plain';
default:
return 'application/octet-stream';
}
};
var GitHubRelease = /** @class */ (function () {
function GitHubRelease(token, username, repository, releaseNotes, commitHash) {
this.token = token;
this.username = username;
this.repository = repository;
this.releaseNotes = releaseNotes;
this.commitHash = commitHash;
this.git = new githubClient_1.default({
required: true,
repo: repository,
var GitHubRelease = /** @class */ (function() {
function GitHubRelease(token, username, repository, releaseNotes, commitHash) {
this.token = token;
this.username = username;
this.repository = repository;
this.releaseNotes = releaseNotes;
this.commitHash = commitHash;
this.git = new githubClient_1.default({
required: true,
repo: repository,
});
}
GitHubRelease.prototype.publishAssets = function(srcLocation, destUrl) {
var _this = this;
// Add the assets. Loop through files in the ci/dist folder and upload each asset.
var files = fs.readdirSync(srcLocation);
return files.map(function(file) {
return tslib_1.__awaiter(_this, void 0, void 0, function() {
var fileStat, fileData;
return tslib_1.__generator(this, function(_a) {
fileStat = fs.statSync(srcLocation + '/' + file);
fileData = fs.readFileSync(srcLocation + '/' + file);
return [
2 /*return*/,
this.git.client.post(destUrl + '?name=' + file, fileData, {
headers: {
'Content-Type': resolveContentType(path.extname(file)),
'Content-Length': fileStat.size,
},
maxContentLength: fileStat.size * 2 * 1024 * 1024,
}),
];
});
}
GitHubRelease.prototype.publishAssets = function (srcLocation, destUrl) {
var _this = this;
// Add the assets. Loop through files in the ci/dist folder and upload each asset.
var files = fs.readdirSync(srcLocation);
return files.map(function (file) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var fileStat, fileData;
return tslib_1.__generator(this, function (_a) {
fileStat = fs.statSync(srcLocation + "/" + file);
fileData = fs.readFileSync(srcLocation + "/" + file);
return [2 /*return*/, this.git.client.post(destUrl + "?name=" + file, fileData, {
headers: {
'Content-Type': resolveContentType(path.extname(file)),
'Content-Length': fileStat.size,
},
maxContentLength: fileStat.size * 2 * 1024 * 1024,
})];
});
}); });
};
GitHubRelease.prototype.release = function () {
var _a, _b, _c, _d;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var ciDir, distDir, distContentDir, pluginJsonFile, pluginInfo, PUBLISH_DIR, commitHash, latestRelease, reason_1, newReleaseResponse, publishPromises, reason_2;
return tslib_1.__generator(this, function (_e) {
switch (_e.label) {
case 0:
ciDir = env_1.getCiFolder();
distDir = path.resolve(ciDir, 'dist');
distContentDir = path.resolve(distDir, getPluginId_1.getPluginId());
pluginJsonFile = path.resolve(distContentDir, 'plugin.json');
pluginInfo = pluginValidation_1.getPluginJson(pluginJsonFile).info;
PUBLISH_DIR = path.resolve(env_1.getCiFolder(), 'packages');
commitHash = this.commitHash || ((_a = pluginInfo.build) === null || _a === void 0 ? void 0 : _a.hash);
_e.label = 1;
case 1:
_e.trys.push([1, 5, , 6]);
return [4 /*yield*/, this.git.client.get("releases/tags/v" + pluginInfo.version)];
case 2:
latestRelease = _e.sent();
if (!(latestRelease.data.tag_name === "v" + pluginInfo.version)) return [3 /*break*/, 4];
return [4 /*yield*/, this.git.client.delete("releases/" + latestRelease.data.id)];
case 3:
_e.sent();
_e.label = 4;
case 4: return [3 /*break*/, 6];
case 5:
reason_1 = _e.sent();
if (reason_1.response.status !== 404) {
// 404 just means no release found. Not an error. Anything else though, re throw the error
throw reason_1;
}
return [3 /*break*/, 6];
case 6:
_e.trys.push([6, 9, , 10]);
return [4 /*yield*/, this.git.client.post('releases', {
tag_name: "v" + pluginInfo.version,
target_commitish: commitHash,
name: "v" + pluginInfo.version,
body: this.releaseNotes,
draft: false,
prerelease: false,
})];
case 7:
newReleaseResponse = _e.sent();
publishPromises = this.publishAssets(PUBLISH_DIR, "https://uploads.github.com/repos/" + this.username + "/" + this.repository + "/releases/" + newReleaseResponse.data.id + "/assets");
return [4 /*yield*/, Promise.all(publishPromises)];
case 8:
_e.sent();
return [3 /*break*/, 10];
case 9:
reason_2 = _e.sent();
console.log(reason_2);
// Rethrow the error so that we can trigger a non-zero exit code to circle-ci
throw reason_2;
case 10: return [2 /*return*/];
}
});
});
};
return GitHubRelease;
}());
});
});
};
GitHubRelease.prototype.release = function() {
var _a, _b, _c, _d;
return tslib_1.__awaiter(this, void 0, void 0, function() {
var ciDir,
distDir,
distContentDir,
pluginJsonFile,
pluginInfo,
PUBLISH_DIR,
commitHash,
latestRelease,
reason_1,
newReleaseResponse,
publishPromises,
reason_2;
return tslib_1.__generator(this, function(_e) {
switch (_e.label) {
case 0:
ciDir = env_1.getCiFolder();
distDir = path.resolve(ciDir, 'dist');
distContentDir = path.resolve(distDir, getPluginId_1.getPluginId());
pluginJsonFile = path.resolve(distContentDir, 'plugin.json');
pluginInfo = pluginValidation_1.getPluginJson(pluginJsonFile).info;
PUBLISH_DIR = path.resolve(env_1.getCiFolder(), 'packages');
commitHash = this.commitHash || ((_a = pluginInfo.build) === null || _a === void 0 ? void 0 : _a.hash);
_e.label = 1;
case 1:
_e.trys.push([1, 5, , 6]);
return [4 /*yield*/, this.git.client.get('releases/tags/v' + pluginInfo.version)];
case 2:
latestRelease = _e.sent();
if (!(latestRelease.data.tag_name === 'v' + pluginInfo.version)) {
return [3 /*break*/, 4];
}
return [4 /*yield*/, this.git.client.delete('releases/' + latestRelease.data.id)];
case 3:
_e.sent();
_e.label = 4;
case 4:
return [3 /*break*/, 6];
case 5:
reason_1 = _e.sent();
if (reason_1.response.status !== 404) {
// 404 just means no release found. Not an error. Anything else though, re throw the error
throw reason_1;
}
return [3 /*break*/, 6];
case 6:
_e.trys.push([6, 9, , 10]);
return [
4 /*yield*/,
this.git.client.post('releases', {
tag_name: 'v' + pluginInfo.version,
target_commitish: commitHash,
name: 'v' + pluginInfo.version,
body: this.releaseNotes,
draft: false,
prerelease: false,
}),
];
case 7:
newReleaseResponse = _e.sent();
publishPromises = this.publishAssets(
PUBLISH_DIR,
'https://uploads.github.com/repos/' +
this.username +
'/' +
this.repository +
'/releases/' +
newReleaseResponse.data.id +
'/assets'
);
return [4 /*yield*/, Promise.all(publishPromises)];
case 8:
_e.sent();
return [3 /*break*/, 10];
case 9:
reason_2 = _e.sent();
console.log(reason_2);
// Rethrow the error so that we can trigger a non-zero exit code to circle-ci
throw reason_2;
case 10:
return [2 /*return*/];
}
});
});
};
return GitHubRelease;
})();
exports.GitHubRelease = GitHubRelease;
//# sourceMappingURL=githubRelease.js.map7027e10521e9
+8 -8
View File
@@ -21,7 +21,6 @@
"scripts": {
"build": "grafana-toolkit toolkit:build",
"clean": "rimraf ./dist ./compiled",
"lint": "eslint src/ --ext=.js,.ts,.tsx",
"precommit": "npm run lint & npm run typecheck",
"typecheck": "tsc --noEmit"
},
@@ -30,7 +29,7 @@
"@babel/core": "7.9.0",
"@babel/preset-env": "7.9.0",
"@grafana/data": "next",
"@grafana/eslint-config": "^1.0.0-rc1",
"@grafana/eslint-config": "2.0.0",
"@grafana/tsconfig": "^1.0.0-rc1",
"@grafana/ui": "next",
"@types/command-exists": "^1.2.0",
@@ -48,8 +47,8 @@
"@types/semver": "^6.0.0",
"@types/tmp": "^0.1.0",
"@types/webpack": "4.41.7",
"@typescript-eslint/eslint-plugin": "2.24.0",
"@typescript-eslint/parser": "2.24.0",
"@typescript-eslint/eslint-plugin": "3.6.0",
"@typescript-eslint/parser": "3.6.0",
"axios": "0.19.2",
"babel-jest": "24.8.0",
"babel-loader": "8.1.0",
@@ -60,10 +59,11 @@
"concurrently": "4.1.0",
"copy-webpack-plugin": "5.1.1",
"css-loader": "^3.0.0",
"eslint": "6.8.0",
"eslint-config-prettier": "6.10.0",
"eslint-plugin-jsdoc": "22.1.0",
"eslint-plugin-prettier": "3.1.2",
"eslint": "7.4.0",
"eslint-config-prettier": "6.11.0",
"eslint-plugin-jsdoc": "28.6.1",
"eslint-plugin-prettier": "3.1.4",
"eslint-plugin-react-hooks": "4.0.5",
"execa": "^1.0.0",
"expect-puppeteer": "4.1.1",
"file-loader": "^4.0.0",
+10 -3
View File
@@ -1,6 +1,13 @@
{
"extends": ["@grafana/eslint-config"],
"rules": {
"no-restricted-imports": [2, "^@grafana/runtime.*", "^@grafana/ui.*", "^@grafana/e2e.*"]
}
"no-restricted-imports": ["error", { "patterns": ["@grafana/runtime", "@grafana/ui", "@grafana/e2e"] }]
},
"overrides": [
{
"files": ["**/*.{test,story}.{ts,tsx}"],
"rules": {
"no-restricted-imports": "off"
}
}
]
}
+1 -1
View File
@@ -1,4 +1,4 @@
'use strict'
'use strict';
if (process.env.NODE_ENV === 'production') {
module.exports = require('./index.production.js');
-1
View File
@@ -21,7 +21,6 @@
"bundle": "rollup -c rollup.config.ts",
"clean": "rimraf ./dist ./compiled",
"docsExtract": "mkdir -p ../../reports/docs && api-extractor run 2>&1 | tee ../../reports/docs/$(basename $(pwd)).log",
"lint": "eslint .storybook/ src/ --ext=.js,.ts,.tsx",
"storybook": "start-storybook -p 9001 -c .storybook -s .storybook/static",
"storybook:build": "build-storybook -o ./dist/storybook -c .storybook -s .storybook/static",
"typecheck": "tsc --noEmit"
@@ -357,6 +357,7 @@ export default class Colors {
let bgColor: Color;
function reset() {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
(color = new Color()),
(bgColor = new Color(true /* background */)),
(brightness = undefined),
-6
View File
@@ -1,6 +0,0 @@
{
"extends": ["@grafana/eslint-config"],
"rules": {
"no-restricted-imports": [2, "^@grafana/runtime.*", "^@grafana/ui.*"]
}
}
@@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
/* eslint-disable import/first */
jest.mock('./scroll-page');
import { scrollBy, scrollTo } from './scroll-page';
@@ -179,8 +178,7 @@ describe('ScrollManager', () => {
it('scrolls to last visible row when boundary is hidden', () => {
const parentOfLastRowWithHiddenChildrenIndex = trace.spans.length - 2;
accessors.getBottomRowIndexVisible.mockReturnValue(0);
accessors.getCollapsedChildren = () =>
new Set([trace.spans[parentOfLastRowWithHiddenChildrenIndex].spanID]);
accessors.getCollapsedChildren = () => new Set([trace.spans[parentOfLastRowWithHiddenChildrenIndex].spanID]);
accessors.getSearchedSpanIDs = () => new Set([trace.spans[0].spanID]);
trace.spans[trace.spans.length - 1].references = getRefs(
trace.spans[parentOfLastRowWithHiddenChildrenIndex].spanID
@@ -27,8 +27,7 @@ import renderIntoCanvas, {
const getCanvasWidth = () => window.innerWidth * 2;
const getBgFillRect = items => ({
fillStyle: BG_COLOR,
height:
!items || items.length < MIN_TOTAL_HEIGHT ? MIN_TOTAL_HEIGHT : Math.min(MAX_TOTAL_HEIGHT, items.length),
height: !items || items.length < MIN_TOTAL_HEIGHT ? MIN_TOTAL_HEIGHT : Math.min(MAX_TOTAL_HEIGHT, items.length),
width: getCanvasWidth(),
x: 0,
y: 0,
@@ -125,8 +124,7 @@ describe('renderIntoCanvas()', () => {
{ input: items[1].serviceName, output: [1, 1, 1] },
{ input: items[2].serviceName, output: [2, 2, 2] },
];
const cHeight =
items.length < MIN_TOTAL_HEIGHT ? MIN_TOTAL_HEIGHT : Math.min(items.length, MAX_TOTAL_HEIGHT);
const cHeight = items.length < MIN_TOTAL_HEIGHT ? MIN_TOTAL_HEIGHT : Math.min(items.length, MAX_TOTAL_HEIGHT);
const expectedDrawings = [
getBgFillRect(),
@@ -44,7 +44,6 @@ describe('<ListView>', () => {
}
function Item(props) {
// eslint-disable-next-line react/prop-types
const { children, ...rest } = props;
return <div {...rest}>{children}</div>;
}
@@ -71,7 +71,6 @@ describe(ReferencesButton, () => {
// here
const menuInstance = shallow(
shallow(dropdown.first().props().overlay).prop('children')({
// eslint-disable-next-line react/prop-types
Menu: ({ children }) => <div>{children}</div>,
})
);
@@ -49,7 +49,10 @@ describe('<SpanBar>', () => {
logs: [
{
timestamp: 10,
fields: [{ key: 'message', value: 'oh the log message' }, { key: 'something', value: 'else' }],
fields: [
{ key: 'message', value: 'oh the log message' },
{ key: 'something', value: 'else' },
],
},
{
timestamp: 10,
@@ -60,7 +63,10 @@ describe('<SpanBar>', () => {
},
{
timestamp: 20,
fields: [{ key: 'message', value: 'oh the next log message' }, { key: 'more', value: 'stuff' }],
fields: [
{ key: 'message', value: 'oh the next log message' },
{ key: 'more', value: 'stuff' },
],
},
],
},
@@ -106,7 +106,10 @@ describe('<SpanBarRow>', () => {
props.span
);
const spanRow = shallow(<SpanBarRow {...props} span={span} />).dive().dive().dive();
const spanRow = shallow(<SpanBarRow {...props} span={span} />)
.dive()
.dive()
.dive();
const refButton = spanRow.find(ReferencesButton);
expect(refButton.length).toEqual(1);
expect(refButton.at(0).props().tooltipText).toEqual('Contains multiple references');
@@ -128,7 +131,10 @@ describe('<SpanBarRow>', () => {
},
props.span
);
const spanRow = shallow(<SpanBarRow {...props} span={span} />).dive().dive().dive();
const spanRow = shallow(<SpanBarRow {...props} span={span} />)
.dive()
.dive()
.dive();
const refButton = spanRow.find(ReferencesButton);
expect(refButton.length).toEqual(1);
expect(refButton.at(0).props().tooltipText).toEqual('This span is referenced by another span');
@@ -158,7 +164,10 @@ describe('<SpanBarRow>', () => {
},
props.span
);
const spanRow = shallow(<SpanBarRow {...props} span={span} />).dive().dive().dive();
const spanRow = shallow(<SpanBarRow {...props} span={span} />)
.dive()
.dive()
.dive();
const refButton = spanRow.find(ReferencesButton);
expect(refButton.length).toEqual(1);
expect(refButton.at(0).props().tooltipText).toEqual('This span is referenced by multiple other spans');
@@ -19,7 +19,10 @@ import AccordianKeyValues, { KeyValuesSummary } from './AccordianKeyValues';
import * as markers from './AccordianKeyValues.markers';
import KeyValuesTable from './KeyValuesTable';
const tags = [{ key: 'span.kind', value: 'client' }, { key: 'omg', value: 'mos-def' }];
const tags = [
{ key: 'span.kind', value: 'client' },
{ key: 'omg', value: 'mos-def' },
];
describe('<KeyValuesSummary>', () => {
let wrapper;
@@ -24,11 +24,17 @@ describe('<AccordianLogs>', () => {
const logs = [
{
timestamp: 10,
fields: [{ key: 'message', value: 'oh the log message' }, { key: 'something', value: 'else' }],
fields: [
{ key: 'message', value: 'oh the log message' },
{ key: 'something', value: 'else' },
],
},
{
timestamp: 20,
fields: [{ key: 'message', value: 'oh the next log message' }, { key: 'more', value: 'stuff' }],
fields: [
{ key: 'message', value: 'oh the next log message' },
{ key: 'more', value: 'stuff' },
],
},
];
const props = {
@@ -112,7 +112,6 @@ describe('<KeyValuesTable>', () => {
const overlay = shallow(dropdown.prop('overlay'));
// We have some wrappers here that dynamically inject specific component so we need to traverse a bit
// here
// eslint-disable-next-line react/prop-types
const menu = shallow(overlay.prop('children')({ Menu: ({ children }) => <div>{children}</div> }));
const anchors = menu.find(LinkValue);
expect(anchors).toHaveLength(2);
@@ -19,7 +19,10 @@ import TextList from './TextList';
describe('<TextList>', () => {
let wrapper;
const data = [{ key: 'span.kind', value: 'client' }, { key: 'omg', value: 'mos-def' }];
const data = [
{ key: 'span.kind', value: 'client' },
{ key: 'omg', value: 'mos-def' },
];
beforeEach(() => {
wrapper = shallow(<TextList data={data} />);
@@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
/* eslint-disable import/first */
jest.mock('../utils');
import React from 'react';
@@ -53,11 +52,17 @@ describe('<SpanDetail>', () => {
span.logs = [
{
timestamp: 10,
fields: [{ key: 'message', value: 'oh the log message' }, { key: 'something', value: 'else' }],
fields: [
{ key: 'message', value: 'oh the log message' },
{ key: 'something', value: 'else' },
],
},
{
timestamp: 20,
fields: [{ key: 'message', value: 'oh the next log message' }, { key: 'more', value: 'stuff' }],
fields: [
{ key: 'message', value: 'oh the next log message' },
{ key: 'more', value: 'stuff' },
],
},
];
@@ -141,9 +146,7 @@ describe('<SpanDetail>', () => {
});
it('renders the process tags', () => {
const target = (
<AccordianKeyValues data={span.process.tags} label="Process" isOpen={detailState.isProcessOpen} />
);
const target = <AccordianKeyValues data={span.process.tags} label="Process" isOpen={detailState.isProcessOpen} />;
expect(wrapper.containsMatchingElement(target)).toBe(true);
wrapper.find({ data: span.process.tags }).simulate('toggle');
expect(props.processToggle).toHaveBeenLastCalledWith(span.spanID);
@@ -48,7 +48,10 @@ describe('<SpanDetailRow>', () => {
props.logsToggle.mockReset();
props.processToggle.mockReset();
props.tagsToggle.mockReset();
wrapper = shallow(<SpanDetailRow {...props} />).dive().dive().dive();
wrapper = shallow(<SpanDetailRow {...props} />)
.dive()
.dive()
.dive();
});
it('renders without exploding', () => {
@@ -19,7 +19,7 @@ import IoIosArrowDown from 'react-icons/lib/io/ios-arrow-down';
import SpanTreeOffset, { getStyles } from './SpanTreeOffset';
import spanAncestorIdsSpy from '../utils/span-ancestor-ids';
import {defaultTheme} from "../Theme";
import { defaultTheme } from '../Theme';
jest.mock('../utils/span-ancestor-ids');
@@ -43,13 +43,19 @@ describe('SpanTreeOffset', () => {
spanID: ownSpanID,
},
};
wrapper = shallow(<SpanTreeOffset {...props} />).dive().dive().dive();
wrapper = shallow(<SpanTreeOffset {...props} />)
.dive()
.dive()
.dive();
});
describe('.SpanTreeOffset--indentGuide', () => {
it('renders only one .SpanTreeOffset--indentGuide for entire trace if span has no ancestors', () => {
spanAncestorIdsSpy.mockReturnValue([]);
wrapper = shallow(<SpanTreeOffset {...props} />).dive().dive().dive();
wrapper = shallow(<SpanTreeOffset {...props} />)
.dive()
.dive()
.dive();
const indentGuides = wrapper.find('[data-test-id="SpanTreeOffset--indentGuide"]');
expect(indentGuides.length).toBe(1);
expect(indentGuides.prop('data-ancestor-id')).toBe(specialRootID);
@@ -65,7 +71,10 @@ describe('SpanTreeOffset', () => {
it('adds .is-active to correct indentGuide', () => {
props.hoverIndentGuideIds = new Set([parentSpanID]);
wrapper = shallow(<SpanTreeOffset {...props} />).dive().dive().dive();
wrapper = shallow(<SpanTreeOffset {...props} />)
.dive()
.dive()
.dive();
const styles = getStyles(defaultTheme);
const activeIndentGuide = wrapper.find(`.${styles.indentGuideActive}`);
expect(activeIndentGuide.length).toBe(1);
@@ -86,12 +86,8 @@ describe('<TimelineColumnResizer>', () => {
it('does not render a dragging indicator when not dragging', () => {
const styles = getStyles();
expect(wrapper.find('[data-test-id="TimelineColumnResizer--dragger"]').prop('style').right).toBe(
undefined
);
expect(wrapper.find('[data-test-id="TimelineColumnResizer--dragger"]').prop('className')).toBe(
styles.dragger
);
expect(wrapper.find('[data-test-id="TimelineColumnResizer--dragger"]').prop('style').right).toBe(undefined);
expect(wrapper.find('[data-test-id="TimelineColumnResizer--dragger"]').prop('className')).toBe(styles.dragger);
});
it('renders a dragging indicator when dragging', () => {
@@ -159,12 +159,7 @@ describe('<TimelineViewingLayer>', () => {
.find('[data-test-id="Dragged"]')
.prop('className')
.indexOf(
cx(
styles.dragged,
styles.draggedDraggingLeft,
styles.draggedDraggingRight,
styles.draggedReframeDrag
)
cx(styles.dragged, styles.draggedDraggingLeft, styles.draggedDraggingRight, styles.draggedReframeDrag)
) >= 0
).toBe(true);
});
@@ -178,12 +173,7 @@ describe('<TimelineViewingLayer>', () => {
.find('[data-test-id="Dragged"]')
.prop('className')
.indexOf(
cx(
styles.dragged,
styles.draggedDraggingLeft,
styles.draggedDraggingRight,
styles.draggedShiftDrag
)
cx(styles.dragged, styles.draggedDraggingLeft, styles.draggedDraggingRight, styles.draggedShiftDrag)
) >= 0
).toBe(true);
});
@@ -49,7 +49,10 @@ describe('<TraceTimelineViewer>', () => {
let wrapper;
beforeEach(() => {
wrapper = shallow(<TraceTimelineViewer {...props} />).dive().dive().dive();
wrapper = shallow(<TraceTimelineViewer {...props} />)
.dive()
.dive()
.dive();
});
it('it does not explode', () => {
@@ -85,8 +85,7 @@ describe('TraceTimelineViewer/utils', () => {
describe('spanContainsErredSpan()', () => {
it('returns true only when a descendant has an error tag', () => {
const errorTag = { key: 'error', type: 'bool', value: true };
const getTags = withError =>
withError ? traceGenerator.tags().concat(errorTag) : traceGenerator.tags();
const getTags = withError => (withError ? traceGenerator.tags().concat(errorTag) : traceGenerator.tags());
// Using a string to generate the test spans. Each line results in a span. The
// left number indicates whether or not the generated span has a descendant
+3 -3
View File
@@ -16,12 +16,12 @@ import ease from 'tween-functions';
import { TNil } from './types';
interface ITweenState {
interface TweenState {
done: boolean;
value: number;
}
type TTweenCallback = (state: ITweenState) => void;
type TTweenCallback = (state: TweenState) => void;
type TTweenOptions = {
delay?: number;
@@ -98,7 +98,7 @@ export default class Tween {
this.callbackUpdate = undefined;
}
getCurrent(): ITweenState {
getCurrent(): TweenState {
const t = Date.now() - this.startTime;
if (t <= 0) {
// still in the delay period
@@ -17,7 +17,7 @@ import { shallow } from 'enzyme';
import debounceMock from 'lodash/debounce';
import UiFindInput from './UiFindInput';
import {UIInput} from "../uiElementsContext";
import { UIInput } from '../uiElementsContext';
jest.mock('lodash/debounce');
@@ -58,8 +58,8 @@ describe('UiFindInput', () => {
});
it('renders props.uiFind when state.ownInputValue is `undefined`', () => {
wrapper.setProps({value: uiFind});
wrapper.setProps({ value: uiFind });
expect(wrapper.find(UIInput).prop('value')).toBe(uiFind);
});
})
});
});
@@ -52,15 +52,14 @@ function getParentSpanId(span, levels) {
function attachReferences(spans, depth, spansPerLevel) {
let levels = [[getSpanId(spans[0])]];
const duplicateLevelFilter = currentLevels => span =>
!currentLevels.find(level => level.indexOf(span.spanID) >= 0);
const duplicateLevelFilter = currentLevels => span => !currentLevels.find(level => level.indexOf(span.spanID) >= 0);
while (levels.length < depth) {
const remainingSpans = spans.filter(duplicateLevelFilter(levels));
if (remainingSpans.length <= 0) break;
const newLevel = chance
.pickset(remainingSpans, spansPerLevel || chance.integer({ min: 4, max: 8 }))
.map(getSpanId);
if (remainingSpans.length <= 0) {
break;
}
const newLevel = chance.pickset(remainingSpans, spansPerLevel || chance.integer({ min: 4, max: 8 })).map(getSpanId);
levels.push(newLevel);
}
@@ -37,12 +37,16 @@ export default class PathElem {
result.push(current);
current = current.externalSideNeighbor;
}
if (this.distance < 0) result.reverse();
if (this.distance < 0) {
result.reverse();
}
return result;
}
get externalSideNeighbor(): PathElem | null | undefined {
if (!this.distance) return null;
if (!this.distance) {
return null;
}
return this.memberOf.members[this.memberIdx + Math.sign(this.distance)];
}
@@ -53,12 +57,16 @@ export default class PathElem {
result.push(current);
current = current.focalSideNeighbor;
}
if (this.distance > 0) result.reverse();
if (this.distance > 0) {
result.reverse();
}
return result;
}
get focalSideNeighbor(): PathElem | null {
if (!this.distance) return null;
if (!this.distance) {
return null;
}
return this.memberOf.members[this.memberIdx - Math.sign(this.distance)];
}
@@ -49,21 +49,9 @@ export const afterPayloadElem = simplePayloadElemMaker('after');
export const lastPayloadElem = simplePayloadElemMaker('last');
export const shortPath = [beforePayloadElem, focalPayloadElem];
export const simplePath = [
firstPayloadElem,
beforePayloadElem,
focalPayloadElem,
afterPayloadElem,
lastPayloadElem,
];
export const simplePath = [firstPayloadElem, beforePayloadElem, focalPayloadElem, afterPayloadElem, lastPayloadElem];
export const longSimplePath = pathLengthener(simplePath);
export const noFocalPath = [
firstPayloadElem,
beforePayloadElem,
midPayloadElem,
afterPayloadElem,
lastPayloadElem,
];
export const noFocalPath = [firstPayloadElem, beforePayloadElem, midPayloadElem, afterPayloadElem, lastPayloadElem];
export const doubleFocalPath = [
firstPayloadElem,
beforePayloadElem,
@@ -151,7 +151,10 @@ describe('createTestFunction()', () => {
});
describe('getParameterInArray()', () => {
const data = [{ key: 'mykey', value: 'ok' }, { key: 'otherkey', value: 'v' }];
const data = [
{ key: 'mykey', value: 'ok' },
{ key: 'otherkey', value: 'v' },
];
it('returns an entry that is present', () => {
expect(getParameterInArray('mykey', data)).toBe(data[0]);
@@ -224,12 +227,19 @@ describe('getParameterInAncestor()', () => {
{ key: 'd', value: 'd3' },
],
},
tags: [{ key: 'a', value: 'a2' }, { key: 'b', value: 'b2' }, { key: 'c', value: 'c2' }],
tags: [
{ key: 'a', value: 'a2' },
{ key: 'b', value: 'b2' },
{ key: 'c', value: 'c2' },
],
},
{
depth: 2,
process: {
tags: [{ key: 'a', value: 'a1' }, { key: 'b', value: 'b1' }],
tags: [
{ key: 'a', value: 'a1' },
{ key: 'b', value: 'b1' },
],
},
tags: [{ key: 'a', value: 'a0' }],
},
@@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
/* eslint-disable import/first */
jest.mock('./Tween');
import { scrollBy, scrollTo, cancel } from './scroll-page';
@@ -28,7 +28,7 @@ function _onTweenUpdate({ done, value }: { done: boolean; value: number }) {
}
}
export function scrollBy(yDelta: number, appendToLast: boolean = false) {
export function scrollBy(yDelta: number, appendToLast = false) {
const { scrollY } = window;
let targetFrom = scrollY;
if (appendToLast && lastTween) {
@@ -24,10 +24,7 @@ export const getSpanTimestamp = span => span.startTime;
export const getSpanProcessId = span => span.processID;
export const getSpanReferences = span => span.references || [];
export const getSpanReferenceByType = createSelector(
createSelector(
({ span }) => span,
getSpanReferences
),
createSelector(({ span }) => span, getSpanReferences),
({ type }) => type,
(references, type) => references.find(ref => ref.refType === type)
);
@@ -49,10 +46,7 @@ export const getSpanProcess = span => {
return span.process;
};
export const getSpanServiceName = createSelector(
getSpanProcess,
getProcessServiceName
);
export const getSpanServiceName = createSelector(getSpanProcess, getProcessServiceName);
export const filterSpansForTimestamps = createSelector(
({ spans }) => spans,
@@ -73,16 +67,14 @@ export const filterSpansForText = createSelector(
.map(({ original }) => original)
);
const getTextFilterdSpansAsMap = createSelector(
filterSpansForText,
matchingSpans =>
matchingSpans.reduce(
(obj, span) => ({
...obj,
[getSpanId(span)]: span,
}),
{}
)
const getTextFilterdSpansAsMap = createSelector(filterSpansForText, matchingSpans =>
matchingSpans.reduce(
(obj, span) => ({
...obj,
[getSpanId(span)]: span,
}),
{}
)
);
export const highlightSpansForTextFilter = createSelector(
@@ -42,9 +42,7 @@ it('getSpanTimestamp() should return the timestamp of the span', () => {
});
it('getSpanReferences() should return the span reference array', () => {
expect(spanSelectors.getSpanReferences(generatedTrace.spans[0])).toEqual(
generatedTrace.spans[0].references
);
expect(spanSelectors.getSpanReferences(generatedTrace.spans[0])).toEqual(generatedTrace.spans[0].references);
});
it('getSpanReferences() should return empty array for null references', () => {
@@ -13,7 +13,7 @@
// limitations under the License.
// See https://github.com/jaegertracing/jaeger-ui/issues/115 for details.
// eslint-disable-next-line import/prefer-default-export
export const followsFromRef = {
processes: {
p1: {
@@ -42,9 +42,8 @@ const getSpanWithProcess = createSelector(
})
);
export const getTraceSpansAsMap = createSelector(
getTraceSpans,
spans => spans.reduce((map, span) => map.set(getSpanId(span), span), new Map())
export const getTraceSpansAsMap = createSelector(getTraceSpans, spans =>
spans.reduce((map, span) => map.set(getSpanId(span), span), new Map())
);
export const TREE_ROOT_ID = '__root__';
@@ -107,32 +106,23 @@ export const hydrateSpansWithProcesses = trace => {
};
};
export const getTraceSpanCount = createSelector(
getTraceSpans,
spans => spans.length
export const getTraceSpanCount = createSelector(getTraceSpans, spans => spans.length);
export const getTraceTimestamp = createSelector(getTraceSpans, spans =>
spans.reduce(
(prevTimestamp, span) => (prevTimestamp ? Math.min(prevTimestamp, getSpanTimestamp(span)) : getSpanTimestamp(span)),
null
)
);
export const getTraceTimestamp = createSelector(
getTraceSpans,
spans =>
spans.reduce(
(prevTimestamp, span) =>
prevTimestamp ? Math.min(prevTimestamp, getSpanTimestamp(span)) : getSpanTimestamp(span),
null
)
);
export const getTraceDuration = createSelector(
getTraceSpans,
getTraceTimestamp,
(spans, timestamp) =>
spans.reduce(
(prevDuration, span) =>
prevDuration
? Math.max(getSpanTimestamp(span) - timestamp + getSpanDuration(span), prevDuration)
: getSpanDuration(span),
null
)
export const getTraceDuration = createSelector(getTraceSpans, getTraceTimestamp, (spans, timestamp) =>
spans.reduce(
(prevDuration, span) =>
prevDuration
? Math.max(getSpanTimestamp(span) - timestamp + getSpanDuration(span), prevDuration)
: getSpanDuration(span),
null
)
);
export const getTraceEndTimestamp = createSelector(
@@ -150,36 +140,22 @@ export const getParentSpan = createSelector(
.sort((spanA, spanB) => numberSortComparator(getSpanTimestamp(spanA), getSpanTimestamp(spanB)))[0]
);
export const getTraceDepth = createSelector(
getTraceSpanIdsAsTree,
spanTree => spanTree.depth - 1
);
export const getTraceDepth = createSelector(getTraceSpanIdsAsTree, spanTree => spanTree.depth - 1);
export const getSpanDepthForTrace = createSelector(
createSelector(
state => state.trace,
getTraceSpanIdsAsTree
),
createSelector(
state => state.span,
getSpanId
),
createSelector(state => state.trace, getTraceSpanIdsAsTree),
createSelector(state => state.span, getSpanId),
(node, spanID) => node.getPath(spanID).length - 1
);
export const getTraceServices = createSelector(
getTraceProcesses,
processes =>
Object.keys(processes).reduce(
(services, processID) => services.add(getProcessServiceName(processes[processID])),
new Set()
)
export const getTraceServices = createSelector(getTraceProcesses, processes =>
Object.keys(processes).reduce(
(services, processID) => services.add(getProcessServiceName(processes[processID])),
new Set()
)
);
export const getTraceServiceCount = createSelector(
getTraceServices,
services => services.size
);
export const getTraceServiceCount = createSelector(getTraceServices, services => services.size);
// establish constants to determine how math should be handled
// for nanosecond-to-millisecond conversions.
@@ -188,9 +164,8 @@ export const DURATION_FORMATTERS = {
s: formatSecondTime,
};
const getDurationFormatterForTrace = createSelector(
getTraceDuration,
totalDuration => (totalDuration >= ONE_SECOND ? DURATION_FORMATTERS.s : DURATION_FORMATTERS.ms)
const getDurationFormatterForTrace = createSelector(getTraceDuration, totalDuration =>
totalDuration >= ONE_SECOND ? DURATION_FORMATTERS.s : DURATION_FORMATTERS.ms
);
export const formatDurationForUnit = createSelector(
@@ -201,10 +176,7 @@ export const formatDurationForUnit = createSelector(
export const formatDurationForTrace = createSelector(
({ duration }) => duration,
createSelector(
({ trace }) => trace,
getDurationFormatterForTrace
),
createSelector(({ trace }) => trace, getDurationFormatterForTrace),
(duration, formatter) => formatter(duration)
);
@@ -216,25 +188,16 @@ export const getSortedSpans = createSelector(
[...spans].sort((spanA, spanB) => dir * comparator(selector(spanA, trace), selector(spanB, trace)))
);
const getTraceSpansByHierarchyPosition = createSelector(
getTraceSpanIdsAsTree,
tree => {
const hierarchyPositionMap = new Map();
let i = 0;
tree.walk(spanID => hierarchyPositionMap.set(spanID, i++));
return hierarchyPositionMap;
}
);
const getTraceSpansByHierarchyPosition = createSelector(getTraceSpanIdsAsTree, tree => {
const hierarchyPositionMap = new Map();
let i = 0;
tree.walk(spanID => hierarchyPositionMap.set(spanID, i++));
return hierarchyPositionMap;
});
export const getTreeSizeForTraceSpan = createSelector(
createSelector(
state => state.trace,
getTraceSpanIdsAsTree
),
createSelector(
state => state.span,
getSpanId
),
createSelector(state => state.trace, getTraceSpanIdsAsTree),
createSelector(state => state.span, getSpanId),
(tree, spanID) => {
const node = tree.find(spanID);
if (!node) {
@@ -245,20 +208,14 @@ export const getTreeSizeForTraceSpan = createSelector(
);
export const getSpanHierarchySortPositionForTrace = createSelector(
createSelector(
({ trace }) => trace,
getTraceSpansByHierarchyPosition
),
createSelector(({ trace }) => trace, getTraceSpansByHierarchyPosition),
({ span }) => span,
(hierarchyPositionMap, span) => hierarchyPositionMap.get(getSpanId(span))
);
export const getTraceName = createSelector(
createSelector(
createSelector(
hydrateSpansWithProcesses,
getParentSpan
),
createSelector(hydrateSpansWithProcesses, getParentSpan),
createStructuredSelector({
name: getSpanName,
serviceName: getSpanServiceName,
@@ -269,10 +226,7 @@ export const getTraceName = createSelector(
export const omitCollapsedSpans = createSelector(
({ spans }) => spans,
createSelector(
({ trace }) => trace,
getTraceSpanIdsAsTree
),
createSelector(({ trace }) => trace, getTraceSpanIdsAsTree),
({ collapsed }) => collapsed,
(spans, tree, collapse) => {
const hiddenSpanIds = collapse.reduce((result, collapsedSpanId) => {
@@ -313,9 +267,7 @@ export const enforceUniqueSpanIds = createSelector(
return {
...trace,
spans: spans.reduce((result, span) => {
const spanID = map.has(getSpanId(span))
? `${getSpanId(span)}_${map.get(getSpanId(span))}`
: getSpanId(span);
const spanID = map.has(getSpanId(span)) ? `${getSpanId(span)}_${map.get(getSpanId(span))}` : getSpanId(span);
const updatedSpan = { ...span, spanID };
if (spanID !== getSpanId(span)) {
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
export type ApiError = // eslint-disable-line import/prefer-default-export
export type ApiError =
| string
| {
message: string;
@@ -41,15 +41,15 @@ export type Config = {
archiveEnabled?: boolean;
deepDependencies?: { menuEnabled?: boolean };
dependencies?: { dagMaxServicesLen?: number; menuEnabled?: boolean };
menu: (ConfigMenuGroup | ConfigMenuItem)[];
menu: Array<ConfigMenuGroup | ConfigMenuItem>;
search?: { maxLookback: { label: string; value: string }; maxLimit: number };
scripts?: TScript[];
topTagPrefixes?: string[];
tracking?: {
cookieToDimension?: {
cookieToDimension?: Array<{
cookie: string;
dimension: string;
}[];
}>;
gaID: string | TNil;
trackErrors: boolean | TNil;
};
@@ -22,4 +22,4 @@ type EmbeddedStateV0 = {
};
};
export type EmbeddedState = EmbeddedStateV0; // eslint-disable-line import/prefer-default-export
export type EmbeddedState = EmbeddedStateV0;
@@ -42,7 +42,7 @@ export type TraceSummary = {
traceID: string;
numberOfErredSpans: number;
numberOfSpans: number;
services: { name: string; numberOfSpans: number }[];
services: Array<{ name: string; numberOfSpans: number }>;
};
export type TraceSummaries = {
@@ -174,9 +174,7 @@ describe('DraggableManager', () => {
const { type, handler, callback, updateType } = testCase;
const event = { ...baseMouseEvt, type };
handler(event);
expect(callback.mock.calls).toEqual([
[{ event, tag, value, x, manager: instance, type: updateType }],
]);
expect(callback.mock.calls).toEqual([[{ event, tag, value, x, manager: instance, type: updateType }]]);
});
});
});
@@ -294,9 +292,7 @@ describe('DraggableManager', () => {
const { type, handler, callback, updateType } = testCase;
const event = { ...baseMouseEvt, type };
handler(event);
expect(callback.mock.calls).toEqual([
[{ event, tag, value, x, manager: instance, type: updateType }],
]);
expect(callback.mock.calls).toEqual([[{ event, tag, value, x, manager: instance, type: updateType }]]);
});
});
});
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import moment from 'moment';
import moment from 'moment-timezone';
import _round from 'lodash/round';
import { toFloatPrecision } from './number';
@@ -84,9 +84,7 @@ it('createSortClickHandler() should return a function', () => {
const currentSortDir = 1;
const updateSort = sinon.spy();
expect(typeof sortUtils.createSortClickHandler(column, currentSortKey, currentSortDir, updateSort)).toBe(
'function'
);
expect(typeof sortUtils.createSortClickHandler(column, currentSortKey, currentSortDir, updateSort)).toBe('function');
});
it('createSortClickHandler() should call updateSort with the new sort vals', () => {
-15
View File
@@ -1,15 +0,0 @@
// Copyright (c) 2019 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/// <reference path="custom.d.ts" />