diff --git a/.eslintrc.js b/.eslintrc.js index 89d7fc5..3c52494 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,11 +2,11 @@ module.exports = { root: true, env: { es6: true, - node: true + node: true, }, extends: 'plugin:@wordpress/eslint-plugin/recommended', rules: { 'one-var': [ 'error', 'never' ], - 'prefer-arrow-callback': [ 'error' ] - } + 'prefer-arrow-callback': [ 'error' ], + }, }; diff --git a/.npmpackagejsonlintrc.json b/.npmpackagejsonlintrc.json new file mode 100644 index 0000000..a895f17 --- /dev/null +++ b/.npmpackagejsonlintrc.json @@ -0,0 +1,35 @@ +{ + "extends": "@wordpress/npm-package-json-lint-config", + "rules": { + "valid-values-license": [ "error", [ "MIT" ] ], + "description-format": [ + "error", + { + "requireCapitalFirstLetter": true, + "requireEndingPeriod": true + } + ], + "prefer-no-devDependencies": "error", + "require-publishConfig": "error", + "require-repository-directory": "error", + "valid-values-author": [ "error", [ "The WordPress Contributors" ] ], + "valid-values-publishConfig": [ + "error", + [ + { + "access": "public" + } + ] + ] + }, + "overrides": [ + { + "patterns": [ "./package.json" ], + "rules": { + "require-publishConfig": "off", + "require-repository-directory": "off", + "prefer-no-devDependencies": "off" + } + } + ] +} diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..10d5fcc --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,3 @@ +// Import the default config file and expose it in the project root. +// Useful for editor integrations. +module.exports = require('@wordpress/prettier-config'); diff --git a/lib/map_old_to_new_file_path.js b/lib/map_old_to_new_file_path.js index 49f7aae..33ce057 100644 --- a/lib/map_old_to_new_file_path.js +++ b/lib/map_old_to_new_file_path.js @@ -19,10 +19,16 @@ function mapOldToNewFilePath( filePath, fileMappings ) { } // Regex to match the second filename of the diff header. - const headerRegex = new RegExp( '((diff \\-\\-git .* )(' + oldPath + ')(\\n))', 'ig' ); + const headerRegex = new RegExp( + '((diff \\-\\-git .* )(' + oldPath + ')(\\n))', + 'ig' + ); // Regex to match the old and new file name of the chunks within the diff. - const chunkFilenameRegex = new RegExp( '((-{3}|\\+{3})( ' + oldPath + '))', 'ig' ); + const chunkFilenameRegex = new RegExp( + '((-{3}|\\+{3})( ' + oldPath + '))', + 'ig' + ); if ( ! body.match( chunkFilenameRegex ) ) { continue; @@ -35,7 +41,13 @@ function mapOldToNewFilePath( filePath, fileMappings ) { // Logs the mapping. if ( body !== newBody ) { - grunt.log.writeln( 'Old file path ' + oldPath + ' found in patch. This path has been automatically replaced by ' + newPath + '.' ); + grunt.log.writeln( + 'Old file path ' + + oldPath + + ' found in patch. This path has been automatically replaced by ' + + newPath + + '.' + ); } } diff --git a/lib/patch.js b/lib/patch.js index 519d5e2..9022877 100644 --- a/lib/patch.js +++ b/lib/patch.js @@ -52,7 +52,8 @@ module.exports = { try { diff.split( '\n' ).forEach( ( line ) => { // these are often the first line - if ( startsWith( line, 'Index: src/' ) || + if ( + startsWith( line, 'Index: src/' ) || startsWith( line, 'Index: tests/' ) || startsWith( line, 'Index: tools/' ) || startsWith( line, 'diff --git src' ) || @@ -61,13 +62,13 @@ module.exports = { startsWith( line, 'diff --git a/src' ) || startsWith( line, 'diff --git a/test' ) || startsWith( line, 'diff --git a/tools' ) - ) { throw false; } wpDashExceptions.forEach( ( exception ) => { - if ( startsWith( line, 'Index: ' + exception ) || + if ( + startsWith( line, 'Index: ' + exception ) || startsWith( line, 'diff --git ' + exception ) || startsWith( line, 'diff --git a/' + exception ) ) { @@ -76,7 +77,8 @@ module.exports = { } ); noWpDashExceptions.forEach( ( exception ) => { - if ( startsWith( line, 'Index: ' + exception ) || + if ( + startsWith( line, 'Index: ' + exception ) || startsWith( line, 'diff --git ' + exception ) || startsWith( line, 'diff --git a/' + exception ) ) { @@ -84,7 +86,8 @@ module.exports = { } } ); - if ( startsWith( line, 'Index: wp-' ) || + if ( + startsWith( line, 'Index: wp-' ) || startsWith( line, 'Index: trunk/wp-' ) || startsWith( line, 'diff --git wp-' ) || startsWith( line, 'diff --git a/wp-' ) @@ -98,5 +101,4 @@ module.exports = { } return src; }, - }; diff --git a/lib/regex.js b/lib/regex.js index e8f32b6..c32810e 100644 --- a/lib/regex.js +++ b/lib/regex.js @@ -1,6 +1,8 @@ module.exports = { patchAttachments( html ) { - return html.match( /