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

Ags/eslint config alpha #343

Open
wants to merge 2 commits into
base: alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ You may create a `.env.private` with any overrides of the environment settings c

**Note: .env.private should be added to your project's .gitignore so it does not get checked in.**

Local module configuration for TypeScript
-----------------------------------------

#. Copy tsconfig.json into the root of the module
#. Set "rootDir" to the root of the source code folders
#. Set "include" to wildcard patterns specifying the subdirectories/files under rootDir where source code can be found
#. Include any wildcards under rootDir that should be excluded using "exclude"

Development
-----------

Expand Down
3 changes: 2 additions & 1 deletion config/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const { babel } = require('../lib/presets');

module.exports = {
extends: '@edx/eslint-config',
parser: '@babel/eslint-parser',
plugins: ['@typescript-eslint'],
parser: '@typescript-eslint/parser',
parserOptions: {
requireConfigFile: true,
babelOptions: {
Expand Down
4 changes: 3 additions & 1 deletion config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const fs = require('fs');
const { jsWithTs: tsjPreset } = require('ts-jest/presets');

const presets = require('../lib/presets');

Expand Down Expand Up @@ -33,11 +34,12 @@ module.exports = {
'/node_modules/(?!@edx)',
],
transform: {
'^.+\\.[t|j]sx?$': [
'^.+\\.jsx?$': [
'babel-jest',
{
configFile: presets.babel.resolvedFilepath,
},
],
...tsjPreset.transform,
},
};
2 changes: 1 addition & 1 deletion config/webpack.common.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ module.exports = {
// the application being built.
'env.config': false,
},
extensions: ['.js', '.jsx'],
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
};
4 changes: 2 additions & 2 deletions config/webpack.prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ module.exports = merge(commonConfig, {
// The babel-loader transforms newer ES2015+ syntax to older ES5 for older browsers.
// Babel is configured with the .babelrc file at the root of the project.
{
test: /\.(js|jsx)$/,
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules\/(?!@edx)/,
use: {
loader: 'babel-loader',
options: {
configFile: presets.babel.resolvedFilepath,
configFile: presets['babel-typescript'].resolvedFilepath,
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions example/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import config from 'env.config';
import Image from './Image';
import appleUrl, { ReactComponent as Apple } from './apple.svg';
import appleImg from './apple.jpg';

Expand All @@ -19,6 +20,8 @@ export default function App() {
</ul>
<h2>JSX parsing tests</h2>
<Apple style={{ width: '10rem' }} />
<h2>TSX parsing tests</h2>
<Image src={appleUrl} alt="appleFromTsx" style={{ width: '10rem' }} />
<h2>Asset import tests</h2>
<img src={appleUrl} alt="apple" style={{ width: '10rem' }} />
<img src={appleUrl} alt="apple" style={{ width: '10rem' }} />
Expand Down
15 changes: 15 additions & 0 deletions example/src/Image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React, { CSSProperties } from 'react';

type ImageProps = {
src: string;
alt?: string;
style?: CSSProperties;
};

const Image = ({ alt, ...rest }:ImageProps) => <img alt={alt} {...rest} />;

const defaultProps = {
alt: undefined,
style: undefined,
};
Image.defaultProps = defaultProps;
12 changes: 12 additions & 0 deletions example/src/__snapshots__/App.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ exports[`Basic test should render 1`] = `
}
}
/>
<h2>
TSX parsing tests
</h2>
<img
alt="appleFromTsx"
src="icon/mock/path"
style={
Object {
"width": "10rem",
}
}
/>
<h2>
Asset import tests
</h2>
Expand Down
Loading