mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 05:05:48 +08:00
script: cleanup & reduce useless prettier files (#15467)
This commit is contained in:
parent
b1ec61a2da
commit
554fdd4a3c
@ -3,15 +3,19 @@ import { mount } from 'enzyme';
|
||||
import List from '..';
|
||||
|
||||
describe('List Item Layout', () => {
|
||||
const data = [{
|
||||
key: 1,
|
||||
href: 'http://ant.design',
|
||||
title: `ant design`,
|
||||
avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',
|
||||
description: 'Ant Design, a design language for background applications, is refined by Ant UED Team.',
|
||||
content: 'We supply a series of design principles, practical patterns and high quality design resources (Sketch and Axure), to help people create their product prototypes beautifully and efficiently.',
|
||||
extra: 'extra',
|
||||
}];
|
||||
const data = [
|
||||
{
|
||||
key: 1,
|
||||
href: 'http://ant.design',
|
||||
title: `ant design`,
|
||||
avatar: 'https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png',
|
||||
description:
|
||||
'Ant Design, a design language for background applications, is refined by Ant UED Team.',
|
||||
content:
|
||||
'We supply a series of design principles, practical patterns and high quality design resources (Sketch and Axure), to help people create their product prototypes beautifully and efficiently.',
|
||||
extra: 'extra',
|
||||
},
|
||||
];
|
||||
|
||||
it('horizontal itemLayout List which contains string nodes should not be flex container', () => {
|
||||
const wrapper = mount(
|
||||
@ -22,9 +26,14 @@ describe('List Item Layout', () => {
|
||||
I am <span>ant</span> design list item
|
||||
</List.Item>
|
||||
)}
|
||||
/>
|
||||
/>,
|
||||
);
|
||||
expect(wrapper.find('.ant-list-item').at(0).hasClass('ant-list-item-no-flex')).toBe(true);
|
||||
expect(
|
||||
wrapper
|
||||
.find('.ant-list-item')
|
||||
.at(0)
|
||||
.hasClass('ant-list-item-no-flex'),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('horizontal itemLayout List should be flex container defaultly', () => {
|
||||
@ -39,9 +48,14 @@ describe('List Item Layout', () => {
|
||||
/>
|
||||
</List.Item>
|
||||
)}
|
||||
/>
|
||||
/>,
|
||||
);
|
||||
expect(wrapper.find('.ant-list-item').at(0).hasClass('ant-list-item-no-flex')).toBe(false);
|
||||
expect(
|
||||
wrapper
|
||||
.find('.ant-list-item')
|
||||
.at(0)
|
||||
.hasClass('ant-list-item-no-flex'),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('vertical itemLayout List should be flex container when there is extra node', () => {
|
||||
@ -57,9 +71,14 @@ describe('List Item Layout', () => {
|
||||
/>
|
||||
</List.Item>
|
||||
)}
|
||||
/>
|
||||
/>,
|
||||
);
|
||||
expect(wrapper.find('.ant-list-item').at(0).hasClass('ant-list-item-no-flex')).toBe(false);
|
||||
expect(
|
||||
wrapper
|
||||
.find('.ant-list-item')
|
||||
.at(0)
|
||||
.hasClass('ant-list-item-no-flex'),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('vertical itemLayout List should not be flex container when there is not extra node', () => {
|
||||
@ -75,9 +94,14 @@ describe('List Item Layout', () => {
|
||||
/>
|
||||
</List.Item>
|
||||
)}
|
||||
/>
|
||||
/>,
|
||||
);
|
||||
expect(wrapper.find('.ant-list-item').at(0).hasClass('ant-list-item-no-flex')).toBe(true);
|
||||
expect(
|
||||
wrapper
|
||||
.find('.ant-list-item')
|
||||
.at(0)
|
||||
.hasClass('ant-list-item-no-flex'),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('horizontal itemLayout List should accept extra node', () => {
|
||||
@ -92,7 +116,7 @@ describe('List Item Layout', () => {
|
||||
/>
|
||||
</List.Item>
|
||||
)}
|
||||
/>
|
||||
/>,
|
||||
);
|
||||
expect(wrapper.render()).toMatchSnapshot();
|
||||
});
|
||||
|
@ -55,7 +55,7 @@
|
||||
// paragraph
|
||||
.@{skeleton-paragraph-prefix-cls} {
|
||||
padding: 0;
|
||||
|
||||
|
||||
> li {
|
||||
width: 100%;
|
||||
height: 16px;
|
||||
|
@ -1,3 +1,3 @@
|
||||
import demoTest from '../../../tests/shared/demoTest';
|
||||
|
||||
demoTest('tabs', { skip: process.env.REACT === '15' ? ['custom-tab-bar-node.md'] : [] });
|
||||
demoTest('tabs', { skip: process.env.REACT === '15' ? ['custom-tab-bar-node.md'] : [] });
|
||||
|
@ -232,17 +232,17 @@
|
||||
"lint-staged": {
|
||||
"components/**/*.tsx": [
|
||||
"npm run lint-staged:ts",
|
||||
"node ./scripts/pre-prettier.js",
|
||||
"node ./scripts/prettier.js --pre",
|
||||
"git add"
|
||||
],
|
||||
"{tests,site,scripts,components}/**/*.{js,jsx}": [
|
||||
"npm run lint-staged:es",
|
||||
"node ./scripts/pre-prettier.js",
|
||||
"node ./scripts/prettier.js --pre",
|
||||
"git add"
|
||||
],
|
||||
"{site,components}/**/*.less": [
|
||||
"stylelint --syntax less",
|
||||
"node ./scripts/pre-prettier.js",
|
||||
"node ./scripts/prettier.js --pre",
|
||||
"git add"
|
||||
],
|
||||
"components/*/demo/*.md": [
|
||||
|
@ -1,48 +0,0 @@
|
||||
/**
|
||||
* copy to https://github.com/facebook/react/blob/master/scripts/prettier/index.js
|
||||
* prettier api doc https://prettier.io/docs/en/api.html
|
||||
*----------*****--------------
|
||||
* lint file is prettier
|
||||
*----------*****--------------
|
||||
*/
|
||||
|
||||
const prettier = require('prettier');
|
||||
const fs = require('fs');
|
||||
|
||||
const prettierConfigPath = require.resolve('../.prettierrc');
|
||||
|
||||
const files = process.argv.slice(2);
|
||||
|
||||
let didError = false;
|
||||
let didWarn = false;
|
||||
|
||||
files.forEach(file => {
|
||||
const options = prettier.resolveConfig.sync(file, {
|
||||
config: prettierConfigPath,
|
||||
});
|
||||
try {
|
||||
const fileInfo = prettier.getFileInfo.sync(file);
|
||||
if (fileInfo.ignored) {
|
||||
return;
|
||||
}
|
||||
const input = fs.readFileSync(file, 'utf8');
|
||||
const withParserOptions = {
|
||||
...options,
|
||||
parser: fileInfo.inferredParser,
|
||||
};
|
||||
const isPrettier = prettier.check(input, withParserOptions);
|
||||
if (!isPrettier) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`\x1b[31m ${file} is no prettier, please use npm run prettier and git add !`);
|
||||
didWarn = true;
|
||||
}
|
||||
} catch (e) {
|
||||
didError = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (didWarn || didError) {
|
||||
process.exit(1);
|
||||
}
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('\x1b[32m lint prettier success!');
|
@ -1,47 +0,0 @@
|
||||
/**
|
||||
* copy to https://github.com/facebook/react/blob/master/scripts/prettier/index.js
|
||||
* prettier api doc https://prettier.io/docs/en/api.html
|
||||
*----------*****--------------
|
||||
* pre commit prettier file
|
||||
*----------*****--------------
|
||||
*/
|
||||
|
||||
const prettier = require('prettier');
|
||||
const fs = require('fs');
|
||||
|
||||
const prettierConfigPath = require.resolve('../.prettierrc');
|
||||
|
||||
const files = process.argv.slice(2);
|
||||
|
||||
let didError = false;
|
||||
|
||||
files.forEach(file => {
|
||||
const options = prettier.resolveConfig.sync(file, {
|
||||
config: prettierConfigPath,
|
||||
});
|
||||
try {
|
||||
const fileInfo = prettier.getFileInfo.sync(file);
|
||||
if (fileInfo.ignored) {
|
||||
return;
|
||||
}
|
||||
const input = fs.readFileSync(file, 'utf8');
|
||||
const withParserOptions = {
|
||||
...options,
|
||||
parser: fileInfo.inferredParser,
|
||||
};
|
||||
const output = prettier.format(input, withParserOptions);
|
||||
if (output !== input) {
|
||||
fs.writeFileSync(file, output, 'utf8');
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`\x1b[34m ${file} is prettier`);
|
||||
}
|
||||
} catch (e) {
|
||||
didError = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (didError) {
|
||||
process.exit(1);
|
||||
}
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('\x1b[32m prettier success!');
|
@ -9,47 +9,47 @@
|
||||
const glob = require('glob');
|
||||
const prettier = require('prettier');
|
||||
const fs = require('fs');
|
||||
const chalk = require('chalk');
|
||||
const program = require('commander');
|
||||
|
||||
program
|
||||
.option('--pre', 'pre-prettier')
|
||||
.option('--lint', 'lint-prettier')
|
||||
.parse(process.argv);
|
||||
|
||||
const prettierConfigPath = require.resolve('../.prettierrc');
|
||||
|
||||
let didError = false;
|
||||
|
||||
let files = [];
|
||||
if (program.pre) {
|
||||
files = program.args;
|
||||
} else {
|
||||
const ignoreFiles = [
|
||||
'**/node_modules/**',
|
||||
'build/**',
|
||||
'es/**',
|
||||
'lib/**',
|
||||
'**/**.snap',
|
||||
'**/**.map',
|
||||
'**/components/style/color/**',
|
||||
'**/dist/**',
|
||||
'_site/**',
|
||||
];
|
||||
|
||||
const ignoreFiles = [
|
||||
'**/node_modules/**',
|
||||
'build/**',
|
||||
'es/**',
|
||||
'lib/**',
|
||||
'**/**.snap',
|
||||
'**/**.map',
|
||||
'**/components/style/color/**',
|
||||
'**/dist/**',
|
||||
'_site/**',
|
||||
];
|
||||
|
||||
// get all ts files
|
||||
const tsFiles = glob.sync('**/*.ts*', {
|
||||
ignore: ignoreFiles,
|
||||
});
|
||||
files = files.concat(tsFiles);
|
||||
|
||||
// get all js files
|
||||
const jsFiles = glob.sync('**/*.js*', {
|
||||
ignore: ignoreFiles,
|
||||
});
|
||||
files = files.concat(jsFiles);
|
||||
|
||||
// get all less files
|
||||
const lessFiles = glob.sync('**/*.less', {
|
||||
ignore: ignoreFiles,
|
||||
});
|
||||
files = files.concat(lessFiles);
|
||||
|
||||
// get all ts, js, less files
|
||||
['**/*.ts*', '**/*.js*', '**/*.less'].forEach(pattern => {
|
||||
const matchFiles = glob.sync(pattern, {
|
||||
ignore: ignoreFiles,
|
||||
});
|
||||
files = files.concat(matchFiles);
|
||||
});
|
||||
}
|
||||
if (!files.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
let didError = false;
|
||||
let didWarn = false;
|
||||
|
||||
files.forEach(file => {
|
||||
const options = prettier.resolveConfig.sync(file, {
|
||||
config: prettierConfigPath,
|
||||
@ -64,19 +64,28 @@ files.forEach(file => {
|
||||
...options,
|
||||
parser: fileInfo.inferredParser,
|
||||
};
|
||||
const output = prettier.format(input, withParserOptions);
|
||||
if (output !== input) {
|
||||
fs.writeFileSync(file, output, 'utf8');
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`\x1b[34m ${file} is prettier`);
|
||||
if (program.lint) {
|
||||
const isPrettier = prettier.check(input, withParserOptions);
|
||||
if (!isPrettier) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(chalk.red(`${file} is no prettier, please use npm run prettier and git add !`));
|
||||
didWarn = true;
|
||||
}
|
||||
} else {
|
||||
const output = prettier.format(input, withParserOptions);
|
||||
if (output !== input) {
|
||||
fs.writeFileSync(file, output, 'utf8');
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(chalk.blue(`${file} is prettier`));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
didError = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (didError) {
|
||||
if (didWarn || didError) {
|
||||
process.exit(1);
|
||||
}
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('\x1b[32m prettier success!');
|
||||
console.log(chalk.green('prettier success!'));
|
||||
|
@ -35,7 +35,7 @@ class Category extends React.Component<CategoryProps, CategoryState> {
|
||||
}, 2000);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
componentWillUnmount() {
|
||||
window.clearTimeout(this.copyId);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user