Skip to content

Commit

Permalink
fix lint and remove ignore patterns (#21)
Browse files Browse the repository at this point in the history
* fix lint and remove ignore patterns

* remove unnecessary dependencies

Co-authored-by: Xinyi Xu <xinyxu@amazon.com>
  • Loading branch information
sheilaXu and Xinyi Xu authored Jul 12, 2022
1 parent bdf0e23 commit 5608892
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 190 deletions.
9 changes: 3 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ module.exports = {
es6: true,
jest: true,
},
// TODO: remove scene-composer related patterns after aligning scene-composer lint style
ignorePatterns: [
'cypress',
'stencil.config.ts',
'configuration',
'__mocks__',
'packages/scene-composer/src/three/*',
'packages/scene-composer/src/typings.d.ts',
'packages/scene-composer/translations/*',
'packages/scene-composer/stories/*',
'packages/scene-composer/jest.config.js',
// <<< Private repo additions
'packages/scene-composer/src/three/tiles3d/*',
// >>>
],
extends: [
'eslint:recommended',
Expand Down
7 changes: 1 addition & 6 deletions packages/scene-composer/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = {
extends: [
'standard',
'standard-react',
'eslint:recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended',
Expand Down Expand Up @@ -67,9 +66,5 @@ module.exports = {
jest: true,
es6: true,
},
ignorePatterns: [
'src/three/GLTFLoader.js',
'src/three/tiles3d/TilesRenderer.js',
'src/three/tiles3d/TilesRendererBase.js',
],
ignorePatterns: ['src/three/GLTFLoader.js', 'src/three/tiles3d/*'],
};
21 changes: 0 additions & 21 deletions packages/scene-composer/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
import AWS from 'aws-sdk';

function getCredentials() {
const chain = new AWS.CredentialProviderChain([
function () {
return {
accessKeyId: process.env.STORYBOOK_ACCESS_KEY_ID,
secretAccessKey: process.env.STORYBOOK_SECRET_ACCESS_KEY,
sessionToken: process.env.STORYBOOK_SESSION_TOKEN,
};
},
]);
return chain.resolvePromise();
}

export const parameters = {
// actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
Expand All @@ -22,9 +7,3 @@ export const parameters = {
},
},
};

export const loaders = [
async () => ({
awsCredentials: await getCredentials(),
}),
];
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const merge = require('merge');
const tsPreset = require('ts-jest/jest-preset');
const awsuiPreset = require('@awsui/jest-preset');
import merge from 'merge';
import tsPreset from 'ts-jest/jest-preset';
import awsuiPreset from '@awsui/jest-preset';

const { jest } = require('./package.json');
import * as pkg from './package.json';

module.exports = merge.recursive(tsPreset, awsuiPreset, {
const jest = pkg.jest;

export default merge.recursive(tsPreset, awsuiPreset, {
...jest,
verbose: true,
collectCoverageFrom: [
Expand Down
22 changes: 5 additions & 17 deletions packages/scene-composer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,11 @@
"tttsc": "ttsc",
"release": "run-s compile copy-assets",
"copy-assets": "copyfiles -e \"**/*.tsx\" -e \"**/*.ts\" -e \"**/*.snap\" -e \"**/*.js\" -e \"**/*.jsx\" -e \"**/*.json\" \"src/**/*\" dist/",
"test": "jest --config jest.config.js --coverage",
"posttest": "npm run test:lint && jest-coverage-ratchet",
"test:build": "run-s build",
"test:lint": "eslint --ext js --ext jsx --ext ts --ext tsx src tests",
"test:update": "jest --config jest.config.js --updateSnapshot",
"test:unit": "jest --config jest.config.js",
"test:watch": "jest --config jest.config.js --watch",
"format:lint": "eslint --fix --ext js --ext jsx --ext ts --ext tsx src tests",
"format": "run-s format:lint",
"test": "jest --config jest.config.ts --coverage",
"posttest": "jest-coverage-ratchet",
"test:update": "jest --config jest.config.ts --updateSnapshot",
"test:unit": "jest --config jest.config.ts",
"test:watch": "jest --config jest.config.ts --watch",
"storybook": "yarn run build-storybook && start-storybook -s ./dist -h 0.0.0.0 -p 6006",
"build-storybook": "build-storybook",
"extract-msgs": "formatjs extract 'src/**/*.ts*' --ignore='**/*.d.ts' --out-file translations/IotAppKitSceneComposer.en_US.json --id-interpolation-pattern '[sha512:contenthash:base64:6]' --format src/utils/totoro-formatter.js",
Expand All @@ -56,7 +52,6 @@
},
"devDependencies": {
"@awsui/jest-preset": "^2.0.3",
"@babel/core": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"@babel/preset-react": "^7.12.1",
"@babel/runtime": "^7.12.1",
Expand All @@ -74,7 +69,6 @@
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/react-hooks": "^6.0.0",
"@testing-library/user-event": "^7.2.1",
"@types/debug": "^4.1.7",
"@types/jest": "^27.4.1",
"@types/jexl": "^2.2.0",
Expand All @@ -86,25 +80,20 @@
"@types/styled-components": "^5.1.12",
"@types/three": "^0.131.0",
"babel-jest": "^27.0.6",
"babel-loader": "^8.2.2",
"babel-plugin-formatjs": "10.3.18",
"copyfiles": "^2.4.1",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.6",
"eslint": "^7.12.1",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^16.0.3",
"eslint-config-standard-react": "^11.0.1",
"eslint-plugin-promise": "^4.3.1",
"eslint-plugin-standard": "^4.1.0",
"husky": "7.0.4",
"identity-obj-proxy": "^3.0.0",
"jest": "^27.0.6",
"jest-coverage-ratchet": "^0.2.3",
"jest-styled-components": "^7.0.0",
"lodash": "^4.17.21",
"node-sass": "^7.0.0",
"npm-run-all": "^4.1.5",
"postcss": "^8.3.6",
"prettier": "^2.3.2",
"prettier-eslint": "^13.0.0",
Expand Down Expand Up @@ -134,7 +123,6 @@
"@react-three/test-renderer": "^7.0.6",
"@tweenjs/tween.js": "^18.6.4",
"arraybuffer-to-string": "1.0.2",
"aws-sdk": "^2.1043.0",
"debug": "^4.3.4",
"immer": "^9.0.6",
"is-absolute-url": "^4.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as THREE from 'three';
import S3 from 'aws-sdk/clients/s3';

import { GetSceneObjectFunction } from '../interfaces/interfaces';

Expand Down
3 changes: 1 addition & 2 deletions packages/scene-composer/src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ declare module '*.css' {
export default content;
}

interface SvgrComponent
extends React.StatelessComponent<React.SVGAttributes<SVGElement>> {}
interface SvgrComponent extends React.StatelessComponent<React.SVGAttributes<SVGElement>> {}

declare module '*.svg' {
const svgUrl: string;
Expand Down
27 changes: 19 additions & 8 deletions packages/scene-composer/stories/SceneComposer.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React, { ChangeEvent } from 'react';
import { useToolbarActions } from 'storybook-addon-toolbar-actions';
import { boolean, select, text, withKnobs } from '@storybook/addon-knobs';
import AWS from 'aws-sdk';
import { applyMode, Mode, applyDensity, Density } from '@awsui/global-styles';
import { ComponentStory, ComponentMeta, forceReRender } from '@storybook/react';
import { initialize } from '@iot-app-kit/source-iottwinmaker';
import { initialize } from '@iot-app-kit/source-iottwinmaker';
import { useCallback, useRef, useState } from '@storybook/addons';
import str2ab from 'string-to-arraybuffer';

Expand Down Expand Up @@ -43,7 +42,7 @@ const commonLoaders = [
async () => ({
configurations: await (async () => {
const awsAccessKeyId = text('awsAccessKeyId', process.env.STORYBOOK_ACCESS_KEY_ID || '');
const awsSecretAccessKey = text('awsSecretAccessKey', process.env.STORYBOOK_SECRET_ACCESS_KEY || '');
const awsSecretAccessKey = text('awsSecretAccessKey', process.env.STORYBOOK_SECRET_ACCESS_KEY || '');
const awsSessionToken = text('awsSessionToken', process.env.STORYBOOK_SESSION_TOKEN || '');
const workspaceId = text('workspaceId', '');
const sceneId = text('sceneId', '');
Expand All @@ -62,11 +61,15 @@ const commonLoaders = [
accessKeyId: awsAccessKeyId,
secretAccessKey: awsSecretAccessKey,
sessionToken: awsSessionToken,
} as AWS.Credentials;
};

const init = initialize(workspaceId, {awsCredentials: credentials, awsRegion: region, tmEndpoint: rociEndpoint});
const init = initialize(workspaceId, {
awsCredentials: credentials,
awsRegion: region,
tmEndpoint: rociEndpoint,
});
const sceneLoader = init.s3SceneLoader(sceneId);
sceneContentUrl = await sceneLoader.getSceneUrl() || '';
sceneContentUrl = (await sceneLoader.getSceneUrl()) || '';

return [sceneContentUrl, sceneLoader.getSceneObject as any];
};
Expand Down Expand Up @@ -113,8 +116,16 @@ const knobsConfigurationDecorator = [
const fileRef = useRef<HTMLInputElement | null>(null);
const [sceneFileLocal, setSceneFileLocal] = useState<string | undefined>(undefined);

const { loadFromAws, sceneContentUrl, uriModifier, theme, density, mode, valueDataBindingProvider, getSceneObjectFunction } =
configurations;
const {
loadFromAws,
sceneContentUrl,
uriModifier,
theme,
density,
mode,
valueDataBindingProvider,
getSceneObjectFunction,
} = configurations;

const cameraTarget = text('camera target ref', '');
const anchorRef = text('anchor ref', '');
Expand Down
2 changes: 1 addition & 1 deletion packages/scene-composer/stories/Trees.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const Basic = () => {
};

export const Expandable = () => {
const [expanded, setExpanded] = useState([])
const [expanded, setExpanded] = useState([]);
return (
<Layout>
<Tree>
Expand Down
4 changes: 1 addition & 3 deletions packages/scene-composer/stories/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
IValueDataBindingProviderState,
} from '../src/interfaces';
import { IValueDataBindingProviderState } from '../src/interfaces';

export interface MockedValueDataBindingProviderStore {
state: IValueDataBindingProviderState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IValueDataBindingProviderState,
} from '../src/interfaces';
import { createDataFrameLabel } from '../src/utils/dataFrameLabelUtils';

import {
asyncLoadEntityOptions,
asyncLoadComponentNameOptions,
Expand All @@ -19,13 +20,7 @@ import {
createIdenticalLabelOption,
} from './useMockedValueDataBindingProviderUtils';
import { FIELD_NAME, MockedValueDataBindingProviderStore } from './types';
import {
COMPONENT_NAME_INDEX,
ENTITY_ID_INDEX,
FIELDS,
MOCK_DELAY,
PROPERTY_NAME_INDEX,
} from './constants';
import { COMPONENT_NAME_INDEX, ENTITY_ID_INDEX, FIELDS, MOCK_DELAY, PROPERTY_NAME_INDEX } from './constants';
export const propertyNames = Object.seal(['temperature']);

export function useMockedValueDataBindingProvider(): IValueDataBindingProvider {
Expand All @@ -45,7 +40,11 @@ export function useMockedValueDataBindingProvider(): IValueDataBindingProvider {
}, []);

return {
setBinding(key: string, binding?: IValueDataBinding, dataBindingConfig?: IDataBindingConfig): IValueDataBindingProviderState {
setBinding(
key: string,
binding?: IValueDataBinding,
dataBindingConfig?: IDataBindingConfig,
): IValueDataBindingProviderState {
// this is an optimization to avoid reinitialize if the state the provider is already synced
if (lastKey.current !== key || !isEqual(binding, lastBinding.current)) {
lastKey.current = key;
Expand All @@ -72,7 +71,12 @@ export function useMockedValueDataBindingProvider(): IValueDataBindingProvider {
}

// initiate loading of entities
asyncLoadEntityOptions(storeRef.current, isDataBindingTemplateProvider, dataBindingConfig, notifyStateChange);
asyncLoadEntityOptions(
storeRef.current,
isDataBindingTemplateProvider,
dataBindingConfig,
notifyStateChange,
);
}

return cloneStoreState(storeRef.current);
Expand All @@ -86,7 +90,12 @@ export function useMockedValueDataBindingProvider(): IValueDataBindingProvider {
storeRef.current.state.selectedOptions[PROPERTY_NAME_INDEX] = undefined as any;

// load component
asyncLoadComponentNameOptions(storeRef.current, isDataBindingTemplateProvider, dataBindingConfig, notifyStateChange);
asyncLoadComponentNameOptions(
storeRef.current,
isDataBindingTemplateProvider,
dataBindingConfig,
notifyStateChange,
);
} else if (fieldName === 'componentName') {
storeRef.current.state.selectedOptions[COMPONENT_NAME_INDEX] = selected;
// clear propertyName selection
Expand Down Expand Up @@ -125,7 +134,7 @@ export function useMockedValueDataBindingProvider(): IValueDataBindingProvider {
setOnStateChangedListener(listener: (state: IValueDataBindingProviderState) => void | undefined) {
storeRef.current.onStateChangedListener = listener;
},
}
};
},
}
};
}
Loading

0 comments on commit 5608892

Please sign in to comment.