Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add eslint-plugin-node rulesets to yarn lint #1714

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7801072
add prod dependency for packaging
hailiu2586 Nov 1, 2019
2efbd56
Merge branch 'stable' into hailiu/server-build
hailiu2586 Nov 28, 2019
3f747fa
explicitly adding format-message-parse to work around yarn workspace …
hailiu2586 Nov 28, 2019
bee898b
allow prepare-prod to use local .tgz install path
hailiu2586 Dec 6, 2019
c8cbf8e
remove ludown to align with stable branch
hailiu2586 Dec 6, 2019
1a750e5
Stable release 12-10-19
cwhitten Dec 11, 2019
262397b
integrate with grpc based app insights
hailiu2586 Dec 12, 2019
3149a20
fix importing of commands/configAppInsights
hailiu2586 Dec 12, 2019
845bc14
Merge branch 'stable' into hailiu/server-build
hailiu2586 Dec 13, 2019
c6a11fd
Merge branch 'hailiu/appinsights' into hailiu/server-build
hailiu2586 Dec 14, 2019
30a4984
revert change to package.json
hailiu2586 Dec 14, 2019
cb4e9e0
add myget feed
hailiu2586 Dec 15, 2019
daec326
revert .npmrc
hailiu2586 Dec 15, 2019
6404d73
add missing dependency
hailiu2586 Dec 15, 2019
3606f37
enable eslint-node-plugin to enforce node/no-extraneous-import rule
hailiu2586 Dec 16, 2019
fed39ab
Merge branch 'master' into hailiu/server-build
hailiu2586 Dec 16, 2019
c9573f2
streamline eslint settings
hailiu2586 Dec 17, 2019
b63d335
integrate async telemetry setup
hailiu2586 Dec 17, 2019
3ead039
fix lg-language-server path
hailiu2586 Dec 18, 2019
88aed66
allow languageServer to take basePath
hailiu2586 Dec 18, 2019
1d5f658
use LgEditorContext to inject language server base path
hailiu2586 Dec 18, 2019
f79adcc
refactor how to config app insights
hailiu2586 Dec 19, 2019
dd46e3d
Merge branch 'master' into hailiu/server-build
hailiu2586 Dec 19, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions Composer/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
'plugin:prettier/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:node/recommended',
'prettier/@typescript-eslint',
'plugin:@bfc/bfcomposer/recommended',
],
Expand Down Expand Up @@ -43,6 +44,17 @@ module.exports = {
'import/first': 'error',
'import/order': ['error', { 'newlines-between': 'always' }],

// node
'node/no-unsupported-features/es-syntax': 'off',
'node/no-missing-import': ['error', {
tryExtensions: ['.js', '.tsx', '.ts']
}],
'node/no-extraneous-import': 'error',
'node/no-unpublished-import': 'off',
'node/no-deprecated-api': ['error', {
ignoreModuleItems: ['url.parse']
}],

// security
'security/detect-buffer-noassert': 'error',
'security/detect-child-process': 'error',
Expand Down Expand Up @@ -81,7 +93,7 @@ module.exports = {
},
overrides: [
{
files: ['**/*.+(test|spec).+(js|jsx|ts|tsx)'],
files: ['**/*.+(test|spec).+(js|jsx|ts|tsx)', 'jest.d.ts'],
env: {
jest: true,
},
Expand All @@ -90,6 +102,8 @@ module.exports = {
'@typescript-eslint/no-object-literal-type-assertion': 'off',
'@typescript-eslint/unbound-method': 'off',

'node/no-missing-import': 'off',

'security/detect-buffer-noassert': 'off',
'security/detect-child-process': 'off',
'security/detect-disable-mustache-escape': 'off',
Expand All @@ -104,6 +118,6 @@ module.exports = {
'security/detect-pseudoRandomBytes': 'off',
'security/detect-unsafe-regex': 'off',
},
},
}
hailiu2586 marked this conversation as resolved.
Show resolved Hide resolved
],
};
2 changes: 1 addition & 1 deletion Composer/.npmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@bfcomposer:registry=https://botbuilder.myget.org/F/botbuilder-declarative/npm/
@bfcomposer:registry=https://botbuilder.myget.org/F/botbuilder-declarative/npm/
1 change: 1 addition & 0 deletions Composer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.1.3",
"eslint-plugin-lodash": "^6.0.0",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-notice": "^0.8.9",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-react": "^7.17.0",
Expand Down
3 changes: 3 additions & 0 deletions Composer/packages/client/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ module.exports = {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
rules: {
'node/no-extraneous-import': 'off',
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

import React, { useState, useEffect } from 'react';
import { initializeIcons } from '@uifabric/icons';
import { LgEditorContext } from '@bfc/code-editor';
import { ShellData, ShellApi } from '@bfc/shared';

import ApiClient from '../messenger/ApiClient';

import getEditor from './EditorMap';

import { BASEPATH } from './../constants';
import ApiClient from './../messenger/ApiClient';
import './extensionContainer.css';

initializeIcons(undefined, { disableWarnings: true });
Expand Down Expand Up @@ -157,7 +157,15 @@ function ExtensionContainer() {

const RealEditor = shellData.data ? getEditor() : null;

return RealEditor && <RealEditor {...shellData} onChange={shellApi.saveData} shellApi={shellApi} />;
if (RealEditor === null) {
return null;
}

return (
<LgEditorContext.Provider value={{ basePath: BASEPATH }}>
<RealEditor {...shellData} onChange={shellApi.saveData} shellApi={shellApi} />
</LgEditorContext.Provider>
);
}

export default ExtensionContainer;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { LgFile } from '@bfc/indexers';
import { editor } from '@bfcomposer/monaco-editor/esm/vs/editor/editor.api';
import { lgIndexer, Diagnostic, combineMessage, isValid } from '@bfc/indexers';

import { BASEPATH } from '../../constants/index';
import { StoreContext } from '../../store';
import { resolveToBasePath } from '../../utils/fileUtil';
import * as lgUtil from '../../utils/lgUtil';

const { check } = lgIndexer;
Expand All @@ -22,7 +24,7 @@ interface CodeEditorProps {
line: number;
}

const lspServerPath = '/lg-language-server';
const lspServerPath = resolveToBasePath(BASEPATH, '/lg-language-server');

export default function CodeEditor(props: CodeEditorProps) {
const { actions } = useContext(StoreContext);
Expand Down
2 changes: 2 additions & 0 deletions Composer/packages/extensions/obiformeditor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
"@bfc/indexers": "*",
"@bfc/shared": "*",
"@bfcomposer/react-jsonschema-form": "1.6.5",
"@emotion/cache": "^10.0.17",
"@emotion/core": "^10.0.17",
"@types/vscode": "^1.40.0",
"@uifabric/fluent-theme": "7.1.4",
"@uifabric/styling": "7.7.1",
"classnames": "^2.2.6",
"format-message": "^6.2.1",
"json-schema": "^0.2.5",
"lodash": "^4.17.15",
"nanoid": "^2.0.1",
"office-ui-fabric-react": "7.62.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface LgEditorWidgetProps {
name: string;
value?: string;
height?: number | string;
lgServerPath?: string;
onChange: (template?: string) => void;
}

Expand Down Expand Up @@ -119,7 +120,7 @@ export const LgEditorWidget: React.FC<LgEditorWidgetProps> = props => {
hidePlaceholder={true}
helpURL={LG_HELP}
languageServer={{
path: lspServerPath,
path: props.lgServerPath || lspServerPath,
}}
height={height}
/>
Expand Down
2 changes: 2 additions & 0 deletions Composer/packages/extensions/visual-designer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"lint:fix": "yarn lint --fix"
},
"dependencies": {
"@bfc/indexers": "*",
"@bfc/shared": "*",
"@emotion/cache": "^10.0.17",
"@emotion/core": "^10.0.7",
"@types/react": "16.9.0",
"classnames": "^2.2.6",
Expand Down
4 changes: 4 additions & 0 deletions Composer/packages/lib/code-editor/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ module.exports = {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
rules: {
'node/no-missing-import': 'off',
'node/no-extraneous-import': 'off',
},
};
23 changes: 13 additions & 10 deletions Composer/packages/lib/code-editor/src/LgEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { MonacoServices, MonacoLanguageClient } from 'monaco-languageclient';
import { registerLGLanguage } from './languages';
import { createUrl, createWebSocket, createLanguageClient } from './utils/lspUtil';
import { RichEditor, RichEditorProps } from './RichEditor';
import LgEditorContext from './utils/LgEditorContext';

const LG_HELP =
'https://github.com/microsoft/BotBuilder-Samples/blob/master/experimental/language-generation/docs/lg-file-format.md';
Expand All @@ -27,19 +28,20 @@ export interface LGOption {
};
}

export type LanguageServer = {
host?: string;
hostname?: string;
port?: number | string;
basePath?: string;
path: string;
};

export interface LGLSPEditorProps extends RichEditorProps {
lgOption?: LGOption;
languageServer?:
| {
host?: string;
hostname?: string;
port?: number | string;
path: string;
}
| string;
languageServer?: LanguageServer;
}

const defaultLGServer = {
const defaultLGServer: LanguageServer = {
path: '/lg-language-server',
};
declare global {
Expand All @@ -62,13 +64,14 @@ async function initializeDocuments(lgOption: LGOption | undefined, uri: string)
}

export function LgEditor(props: LGLSPEditorProps) {
const config = React.useContext(LgEditorContext);
const options = {
quickSuggestions: true,
...props.options,
};

const { lgOption, languageServer, ...restProps } = props;
const lgServer = languageServer || defaultLGServer;
const lgServer: LanguageServer = { basePath: config.basePath, ...(languageServer || defaultLGServer) };

const editorWillMount = (monaco: typeof monacoEditor) => {
registerLGLanguage(monaco);
Expand Down
1 change: 1 addition & 0 deletions Composer/packages/lib/code-editor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './JsonEditor';
export * from './LgEditor';
export * from './LuEditor';
export * from './RichEditor';
export { default as LgEditorContext } from './utils/LgEditorContext';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import React from 'react';

const LgEditorContext = React.createContext<{ basePath: string }>({ basePath: '/' });

export default LgEditorContext;
6 changes: 3 additions & 3 deletions Composer/packages/lib/code-editor/src/utils/lspUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import {
LanguageClientOptions,
} from 'monaco-languageclient';

export function createUrl(server: { [key: string]: string } | string): string {
export function createUrl(server: { [key: string]: string | number | undefined } | string): string {
if (typeof server === 'string') {
return normalizeUrl.default(server).replace(/^http/, 'ws');
}
const { host, hostname = location.hostname, port = location.port, path = '/' } = server;
const { host, hostname = location.hostname, port = location.port, path = '/', basePath = '' } = server;
const protocol = location.protocol === 'https:' ? 'wss' : 'ws';
const endHost = host || `${hostname}:${port}`;
return normalizeUrl.default(`${protocol}://${endHost}/${path}`);
return normalizeUrl.default(`${protocol}://${endHost}/${basePath}/${path}`);
}

export function createWebSocket(url: string): WebSocket {
Expand Down
4 changes: 3 additions & 1 deletion Composer/packages/lib/indexers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"@bfcomposer/bf-lu": "1.1.2",
"botbuilder-lg": "4.7.0-preview.93464",
"botframework-expressions": "4.7.0-preview.93464",
"lodash": "^4.17.15"
"format-message": "^6.2.3",
"lodash": "^4.17.15",
"ludown": "^1.3.4"
}
}
1 change: 1 addition & 0 deletions Composer/packages/lib/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"ts-jest": "^24.1.0"
},
"dependencies": {
"botbuilder-lg": "4.7.0-preview.93464",
"json-schema": "^0.2.5",
"nanoid": "^2.1.6"
}
Expand Down
2 changes: 2 additions & 0 deletions Composer/packages/server/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module.exports = {
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
ecmaVersion: 6,
sourceType: 'module',
},
rules: {
'security/detect-non-literal-fs-filename': 'off',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ export class SelfHostBotConnector implements IBotConnector {
constructor(skipLoad?: boolean) {
if (!skipLoad) {
// for production
//eslint-disable-next-line node/no-missing-require
this.buildAsync = require('commands/build').handlerAsync;
//eslint-disable-next-line node/no-missing-require
this.publishAsync = require('commands/publish').handlerAsync;
//eslint-disable-next-line node/no-missing-require
this.getEditingStatusAsync = require('commands/editingStatus').handlerAsync;
//eslint-disable-next-line node/no-missing-require
this.getPublishHistoryAsync = require('commands/getPublishHistory').handlerAsync;
} else {
// for testing this class
Expand Down
44 changes: 29 additions & 15 deletions Composer/packages/server/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import 'dotenv/config';
import path from 'path';
import crypto from 'crypto';
Expand Down Expand Up @@ -41,6 +40,19 @@ const CS_POLICIES = [
'upgrade-insecure-requests;',
];

async function configAppInsightsAsNeeded(): Promise<boolean> {
const appInsightsKey = process.env.SharedAppInsightsKey;
if (appInsightsKey) {
//eslint-disable-next-line node/no-missing-require
const configAppInsights = require('commands/configAppInsights').default as SelfHostCommands.SetupTelemetry;
await configAppInsights(appInsightsKey);

return true;
}

return false;
}

app.all('*', function(req: Request, res: Response, next: NextFunction) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,HEAD,OPTIONS,POST,PUT,DELETE');
Expand Down Expand Up @@ -101,12 +113,6 @@ app.get('*', function(req, res) {
});

const port = process.env.PORT || 5000;
const server = app.listen(port, () => {
if (process.env.NODE_ENV === 'production') {
// eslint-disable-next-line no-console
console.log(`\n\nComposer now running at:\n\nhttp://localhost:${port}\n`);
}
});

const wss: ws.Server = new ws.Server({
noServer: true,
Expand All @@ -121,13 +127,21 @@ function launchLanguageServer(socket: rpc.IWebSocket) {
server.start();
}

attachLSPServer(wss, server, '/lg-language-server', webSocket => {
// launch language server when the web socket is opened
if (webSocket.readyState === webSocket.OPEN) {
launchLanguageServer(webSocket);
} else {
webSocket.on('open', () => {
configAppInsightsAsNeeded().then(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@a-b-r-o-w-n does this refactor meet your requirement on how app insights get configured?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking we could add that in a separate pull request.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const server = app.listen(port, () => {
if (process.env.NODE_ENV === 'production') {
// eslint-disable-next-line no-console
console.log(`\n\nComposer now running at:\n\nhttp://localhost:${port}\n`);
}
});
attachLSPServer(wss, server, `${BASEURL}/lg-language-server`, webSocket => {
// launch language server when the web socket is opened
if (webSocket.readyState === webSocket.OPEN) {
launchLanguageServer(webSocket);
});
}
} else {
webSocket.on('open', () => {
launchLanguageServer(webSocket);
});
}
});
});
3 changes: 3 additions & 0 deletions Composer/packages/server/src/types/selfHostCommands.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ declare namespace SelfHostCommands {
export interface Publish {
(argv: PublishARGV): Promise<string>;
}
export interface SetupTelemetry {
(key: string): Promise<void>;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
},
"dependencies": {
"botbuilder-lg": "4.7.0-preview.93464",
"botframework-expressions": "4.7.0-preview.93464",
"lodash": "^4.17.13",
"request-light": "^0.2.2",
"vscode-languageserver": "^5.3.0-next"
"vscode-languageserver": "^5.3.0-next",
"vscode-languageserver-protocol": "^3.15.0-next.8",
"vscode-languageserver-types": "^3.15.0-next.4",
"vscode-uri": "^1.0.5"
},
"devDependencies": {
"@types/node": "^12.0.4",
Expand Down
Loading