@w5s/eslint-config 1.0.0-alpha.37 → 1.0.0-alpha.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/rules/prettier.js +30 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@w5s/eslint-config",
3
- "version": "1.0.0-alpha.37",
3
+ "version": "1.0.0-alpha.39",
4
4
  "description": "ESLint configuration presets",
5
5
  "keywords": [
6
6
  "eslint",
@@ -51,7 +51,7 @@
51
51
  "@rushstack/eslint-patch": "^1.1.0",
52
52
  "@typescript-eslint/eslint-plugin": "^5.0.0",
53
53
  "@typescript-eslint/parser": "^5.0.0",
54
- "@w5s/prettier-config": "^1.0.0-alpha.1",
54
+ "@w5s/prettier-config": "^1.0.2",
55
55
  "eslint-config-airbnb-base": "^15.0.0",
56
56
  "eslint-config-prettier": "^8.0.0",
57
57
  "eslint-plugin-functional": "^4.2.0",
@@ -97,5 +97,5 @@
97
97
  "publishConfig": {
98
98
  "access": "public"
99
99
  },
100
- "gitHead": "e6b57fb4d5c15057b66ccef776ec225496b012b7"
100
+ "gitHead": "a0e28715a049dcfffbde753363f3133f69549a28"
101
101
  }
package/rules/prettier.js CHANGED
@@ -1,25 +1,44 @@
1
1
  const { error } = require('./_rule.js');
2
2
 
3
- // Try require '@w5s/prettier-config'
4
- const prettierConfig = (() => {
3
+ const getPackageScope = () => {
5
4
  try {
6
- // eslint-disable-next-line global-require
7
- return require('@w5s/prettier-config');
5
+ // eslint-disable-next-line global-require, import/no-dynamic-require
6
+ const { name } = require('../package.json');
7
+ const prefixMatch = (name || '').match(/(@\w+)\//);
8
+ const packageScope = prefixMatch ? prefixMatch[1] : undefined;
9
+ return packageScope;
8
10
  } catch (error_) {
9
11
  // eslint-disable-next-line no-console
10
12
  console.warn(error_);
11
- /** @type {import('@w5s/prettier-config')} */
12
- const defaultConfig = {
13
- trailingComma: 'es5',
14
- };
15
- return defaultConfig;
13
+
14
+ return undefined;
15
+ }
16
+ };
17
+ const getPrettierConfig = (/** @type {string} */ moduleName) => {
18
+ try {
19
+ /** @type {import('prettier').Config} */
20
+ // eslint-disable-next-line global-require, import/no-dynamic-require
21
+ const moduleConfig = require(moduleName);
22
+ return moduleConfig;
23
+ } catch {
24
+ return undefined;
16
25
  }
17
- })();
26
+ };
27
+
28
+ // Try require '@my-organization/prettier-config'
29
+ const getPrettierConfigDefault = () => {
30
+ /** @type {import('prettier').Config} */
31
+ const defaultConfig = {
32
+ trailingComma: 'es5',
33
+ };
34
+ const packageScope = getPackageScope();
35
+ return getPrettierConfig(`${packageScope}/prettier-config`) || defaultConfig;
36
+ };
18
37
 
19
38
  module.exports = {
20
39
  extends: ['prettier'],
21
40
  plugins: ['prettier'],
22
41
  rules: {
23
- 'prettier/prettier': [error, prettierConfig],
42
+ 'prettier/prettier': [error, getPrettierConfigDefault()],
24
43
  },
25
44
  };