Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const preset = config.values().eslintPreset;
const packages = config.values().eslintPeerDependencies;
packages.push('eslint');
if (preset !== 'eslint:recommended') {
packages.push(`eslint-config-${preset}`);
}
// .eslintrc
const eslintrc = json('.eslintrc');
if (!eslintrc.get('extends', '').startsWith(preset)) {
eslintrc.set('extends', preset).save();
}
// package.json
const pkg = packageJson();
// Keep custom extensions
let exts = '';
const lintScript = pkg.getScript('lint');
if (lintScript) {
const args = minimist(lintScript.split(' ').slice(1));
if (args.ext && args.ext !== 'js') {
exts = ` --ext ${args.ext}`;
}
}
pkg
// Remove existing JS linters
.removeScript(/^(lint:js|eslint|jshint|jslint)$/)
.removeScript('test', / (lint|lint:js|eslint|jshint|jslint)( |$)/)
// Add lint script
function task(config) {
config.defaults({
eslintPreset: 'eslint:recommended',
eslintPeerDependencies: [],
});
const preset = config.values().eslintPreset;
const packages = config.values().eslintPeerDependencies;
packages.push('eslint');
if (preset !== 'eslint:recommended') {
packages.push(`eslint-config-${preset}`);
}
// .eslintrc
const eslintrc = json('.eslintrc');
if (!eslintrc.get('extends', '').startsWith(preset)) {
eslintrc.set('extends', preset).save();
}
// package.json
const pkg = packageJson();
// Keep custom extensions
let exts = '';
const lintScript = pkg.getScript('lint');
if (lintScript) {
const args = minimist(lintScript.split(' ').slice(1));
if (args.ext && args.ext !== 'js') {
exts = ` --ext ${args.ext}`;
}
}
if (pkg.get(`devDependencies.eslint`)) {
const eslintignore = lines('.eslintignore').add('coverage/*');
if (hasBabel) {
eslintignore.add('lib/*');
}
eslintignore.save();
}
// Test template for small projects
if (fs.existsSync('index.js') && !fs.existsSync('test')) {
copyFiles(__dirname, 'test.js');
}
// Dependencies
uninstall(oldPackages);
install(packages);
// Suggest jest-codemods if projects used other test frameworks
if (needsMigration) {
console.log(`\nMigrate your tests to Jest:
npm i -g jest-codemods@latest
jest-codemods
More info:
https://github.com/skovhus/jest-codemods
`);
}
};
module.exports.description = 'Adds Jest';
const requireNodeVersion = pkg.get('engines.node');
const minNodeVersion = requireNodeVersion
? semverUtils.parseRange(requireNodeVersion)[0].major
: latestNodeVersion;
// Only LTS or latest
const nodeVersions = range(minNodeVersion, latestNodeVersion + 1).filter(
ver => ver % 2 === 0 || ver === latestNodeVersion
);
travisYml.set('node_js', nodeVersions);
travisYml.save();
// Add Travis package badge to Readme
const url = `https://travis-ci.org/${github}/${pkg.get('name')}`;
markdown(readmeFile).addBadge(`${url}.svg`, url, 'Build Status').save();
console.log(`
1. Activate your repository on Travis CI:
${url}
2. Commit and push your changes
`);
}
// ESLint
if (pkg.get(`devDependencies.eslint`)) {
const eslintignore = lines('.eslintignore').add('coverage/*');
if (hasBabel) {
eslintignore.add('lib/*');
}
eslintignore.save();
}
// Test template for small projects
if (fs.existsSync('index.js') && !fs.existsSync('test')) {
copyFiles(__dirname, 'test.js');
}
// Dependencies
uninstall(oldPackages);
install(packages);
// Suggest jest-codemods if projects used other test frameworks
if (needsMigration) {
console.log(`\nMigrate your tests to Jest:
npm i -g jest-codemods@latest
jest-codemods
More info:
https://github.com/skovhus/jest-codemods
`);
}
};
module.exports.description = 'Adds Jest';
// .npmignore
lines('.npmignore').add('__tests__/').save();
// ESLint
if (pkg.get(`devDependencies.eslint`)) {
const eslintignore = lines('.eslintignore').add('coverage/*');
if (hasBabel) {
eslintignore.add('lib/*');
}
eslintignore.save();
}
// Test template for small projects
if (fs.existsSync('index.js') && !fs.existsSync('test')) {
copyFiles(__dirname, 'test.js');
}
// Dependencies
uninstall(oldPackages);
install(packages);
// Suggest jest-codemods if projects used other test frameworks
if (needsMigration) {
console.log(`\nMigrate your tests to Jest:
npm i -g jest-codemods@latest
jest-codemods
More info:
https://github.com/skovhus/jest-codemods
`);
indent_style: 'tab',
}
: {
indent_style: 'space',
indent_size: indent,
},
{
end_of_line: 'lf',
charset: 'utf-8',
trim_trailing_whitespace: true,
insert_final_newline: true,
}
);
// .editorconfig
const editorconfig = ini('.editorconfig', 'editorconfig.org');
editorconfig.set('root', true).set('*', generalRules);
// Set/update JSON-like section
const jsonSection = editorconfig.get().find(section => /json/.test(section));
if (jsonSection) {
editorconfig.unset(jsonSection);
}
editorconfig.set('*.{' + jsonExtensions.join(',') + '}', jsonRules);
editorconfig.save();
}
'selector-pseudo-class-no-unknown': [
true,
{
ignorePseudoClasses: [
// CSS Modules
'global',
],
},
],
},
})
.save();
}
// package.json
const pkg = packageJson();
pkg
// Add lint script
.setScript('lint:css', `stylelint '**/*${ext}'`)
// Add pretest script
.prependScript('pretest', 'npm run lint:css')
.save();
// Dependencies
install(packages);
}
module.exports = function(config) {
// Require .travis.yml
if (!fs.existsSync('.travis.yml')) {
throw new MrmError(
`Run travis task first:
mrm travis`
);
}
// package.json
const pkg = packageJson();
if (!pkg.getScript('semantic-release')) {
throw new MrmError(
`Setup semantic-release first:
npx semantic-release-cli setup
semantic-release needs to add required auth keys to Travis CI.
WARNING: Do not agree to update your .travis.yml when asked.
More info:
https://github.com/semantic-release/semantic-release#setup
`
);
}
// Remove semantic-release devDependency
module.exports = function() {
// package.json
const pkg = packageJson().merge({
scripts: {
'test:jest': 'jest',
'test:watch': 'jest --watch',
'test:coverage': 'jest --coverage',
},
});
const needsMigration = oldPackages.some(name => pkg.get(`devDependencies.${name}`));
const hasBabel = pkg.get(`devDependencies.babel-core`);
// Babel
if (hasBabel) {
packages.push('babel-jest');
pkg.merge({
jest: {
testPathIgnorePatterns: ['/lib/'],