Skip to content

Commit

Permalink
feat: extend configs from wp-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
g-elwell committed May 17, 2024
1 parent daff4c2 commit 2fd3747
Show file tree
Hide file tree
Showing 41 changed files with 1,838 additions and 7,204 deletions.
1 change: 0 additions & 1 deletion .prettierrc.js

This file was deleted.

4 changes: 0 additions & 4 deletions __tests__/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
const path = require('path');
const mockFs = require('mock-fs');

jest.mock('ora', () => () => ({
start: jest.fn(),
}));

const requiredRealDirs = {
node_modules: mockFs.load(path.resolve(__dirname, '../node_modules')),
src: mockFs.load(path.resolve(__dirname, '../src')),
Expand Down
60 changes: 0 additions & 60 deletions configs/babel.js

This file was deleted.

6 changes: 0 additions & 6 deletions configs/browserlist.js

This file was deleted.

56 changes: 23 additions & 33 deletions configs/eslint.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,13 @@
const babelConfig = require('./babel.js');
const { eslintResolver } = require('./../src/utils/get-alias');
const path = require('path');

module.exports = {
globals: {
__DEV__: true,
__PROD__: true,
__TEST__: true,
wp: true,
},
const eslintConfig = {
extends: ['plugin:@wordpress/eslint-plugin/recommended', 'airbnb', 'prettier'],
env: {
browser: true,
es2021: true,
node: true,
},
extends: ['airbnb', 'prettier', 'plugin:@typescript-eslint/recommended'],
parser: '@babel/eslint-parser',
parserOptions: {
requireConfigFile: false,
babelOptions: {
...babelConfig,
},
env: {
browser: true,
es2021: true,
node: true,
},
settings: {
'import/resolver': eslintResolver(),
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
},
},
plugins: ['@babel', 'react', 'prettier', 'jsdoc', 'import', '@typescript-eslint/eslint-plugin'],
rules: {
complexity: ['error', 10],
'prettier/prettier': 'error',
'prettier/prettier': ['error', require(path.resolve(__dirname, './prettier'))],
'import/no-extraneous-dependencies': [
'error',
{
Expand Down Expand Up @@ -68,5 +40,23 @@ module.exports = {
},
},
],
'@wordpress/no-unsafe-wp-apis': 'warn',
},
};
settings: {
'import/resolver': {
alias: {
map: [
['@Components', path.resolve(process.cwd(), 'src/components')],
['Components', path.resolve(process.cwd(), 'src/components')],
['@Static', path.resolve(process.cwd(), 'src/static')],
['Static', path.resolve(process.cwd(), 'src/static')],
['@Utils', path.resolve(process.cwd(), 'src/utils')],
['Utils', path.resolve(process.cwd(), 'src/utils')],
],
extensions: ['.ts', '.tsx', '.mjs', '.js', '.jsx'],
},
}
},
};

module.exports = eslintConfig;
24 changes: 0 additions & 24 deletions configs/postcss.js

This file was deleted.

9 changes: 7 additions & 2 deletions configs/prettier.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const config = {
const defaultConfig = require('@wordpress/prettier-config');

const prettierConfig = {
...defaultConfig,
tabWidth: 2,
useTabs: false,
printWidth: 100,
trailingComma: 'all',
arrowParens: 'always',
singleQuote: true,
endOfLine: 'auto',
};

module.exports = config;
module.exports = prettierConfig;
13 changes: 11 additions & 2 deletions configs/stylelint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@

module.exports = {
plugins: ['stylelint-scss'],
extends: ["@wordpress/stylelint-config/scss"],
rules: {
// wp overrides
indentation: 2,
'selector-class-pattern': null,
'selector-id-pattern': null,
'max-line-length': 100,
'string-quotes': 'single',
'no-descending-specificity': null,
// our rules
'color-hex-length': 'short',
'color-no-invalid-hex': true,
'function-calc-no-unspaced-operator': true,
Expand Down Expand Up @@ -35,4 +44,4 @@ module.exports = {
'scss/at-if-closing-brace-newline-after': 'always-last-in-chain',
'scss/at-if-closing-brace-space-after': 'always-intermediate',
},
};
};
32 changes: 0 additions & 32 deletions configs/tsconfig.json

This file was deleted.

Empty file removed configs/typescript/dummy.ts
Empty file.
13 changes: 0 additions & 13 deletions configs/typescript/images.d.ts

This file was deleted.

45 changes: 45 additions & 0 deletions configs/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const path = require('path');
const webpack = require('webpack');
const defaultConfig = require('@wordpress/scripts/config/webpack.config');
const ESLintWebpackPlugin = require('eslint-webpack-plugin');
const StyleLintPlugin = require('stylelint-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const eslintConfig = require('./eslint.js');
const styleLintConfig = require('./stylelint.js');

/** @type {webpack.Configuration} */
const webpackConfig = {
...defaultConfig,
plugins: [
...defaultConfig.plugins,
new ESLintWebpackPlugin({
baseConfig: eslintConfig,
}),
new StyleLintPlugin({
config: styleLintConfig,
}),
new CopyWebpackPlugin({
patterns: [
{
from: `static/**/*`,
context: 'src',
noErrorOnMissing: true,
},
],
}),
],
resolve: {
...defaultConfig.resolve,
alias: {
...defaultConfig.resolve.alias,
'@Components': path.resolve(process.cwd(), 'src/components'),
Components: path.resolve(process.cwd(), 'src/components'),
'@Static': path.resolve(process.cwd(), 'src/static'),
Static: path.resolve(process.cwd(), 'src/static'),
'@Utils': path.resolve(process.cwd(), 'src/utils'),
Utils: path.resolve(process.cwd(), 'src/utils'),
},
},
};

module.exports = webpackConfig;
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const webpackConfig = require("./configs/webpack.config");

module.exports = webpackConfig;
Loading

0 comments on commit 2fd3747

Please sign in to comment.