@kaliber/build 0.0.118 → 0.0.119

Sign up to get free protection for your applications and to get access to all the features.
package/.eslintrc CHANGED
@@ -1,7 +1,7 @@
1
1
  // Based on eslint-config-react-app; https://github.com/facebookincubator/create-react-app/blob/cd3d04b71e91f533bdbdc3856775e1da81d445cf/packages/eslint-config-react-app/index.js
2
2
 
3
3
  {
4
- "parser": "babel-eslint",
4
+ "parser": "@babel/eslint-parser",
5
5
  "plugins": ["import", "jsx-a11y", "react", "react-hooks", "@kaliber/eslint-plugin"],
6
6
  "root": true,
7
7
  "env": {
@@ -30,6 +30,10 @@
30
30
  "jsx": true,
31
31
  "generators": true,
32
32
  "experimentalObjectRestSpread": true
33
+ },
34
+ "requireConfigFile": false,
35
+ "babelOptions": {
36
+ "presets": ["@babel/preset-react"]
33
37
  }
34
38
  },
35
39
 
@@ -22,7 +22,6 @@ export function findComponents({ componentName }) {
22
22
 
23
23
  const findComponentCache = getFindComponentCache()
24
24
  const components = findComponentCache[componentName] || []
25
- if (!components.length) console.warn(`Could not find any component with name '${componentName}', dit you render it to the page?`)
26
25
  return components
27
26
 
28
27
  function getFindComponentCache() {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.118",
2
+ "version": "0.0.119",
3
3
  "name": "@kaliber/build",
4
4
  "description": "Zero configuration, opinionated webpack / react build setup",
5
5
  "scripts": {
@@ -16,6 +16,7 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@babel/core": "^7.11.6",
19
+ "@babel/eslint-parser": "^7.16.5",
19
20
  "@babel/plugin-proposal-class-properties": "^7.10.4",
20
21
  "@babel/plugin-proposal-decorators": "^7.10.5",
21
22
  "@babel/plugin-proposal-object-rest-spread": "^7.11.0",
@@ -24,12 +25,11 @@
24
25
  "@babel/plugin-transform-async-to-generator": "^7.10.4",
25
26
  "@babel/plugin-transform-runtime": "^7.11.5",
26
27
  "@babel/preset-env": "^7.11.5",
27
- "@babel/preset-react": "^7.10.4",
28
+ "@babel/preset-react": "^7.16.7",
28
29
  "@babel/runtime": "^7.11.2",
29
30
  "@kaliber/config": "^0.0.8",
30
31
  "@kaliber/eslint-plugin": "*",
31
32
  "ansi-regex": "^5.0.0",
32
- "babel-eslint": "^10.1.0",
33
33
  "babel-loader": "^8.0.6",
34
34
  "cache-loader": "^4.1.0",
35
35
  "classnames": "^2.2.6",
@@ -1,9 +1,12 @@
1
1
  module.exports = {
2
2
  flexChildProps: [
3
- 'flex', 'flex-grow', 'flex-shrink', 'flex-basis', 'order',
3
+ 'flex', 'flex-grow', 'flex-shrink', 'flex-basis',
4
4
  ],
5
5
  gridChildProps: [
6
6
  'grid', 'grid-area', 'grid-column', 'grid-row',
7
7
  'grid-column-start', 'grid-column-end', 'grid-row-start', 'grid-row-end',
8
8
  ],
9
+ flexOrGridChildProps: [
10
+ 'order'
11
+ ],
9
12
  }
@@ -31,6 +31,7 @@ function checkRuleRelation({ rule, triggerProperties, rulesToCheck, requiredProp
31
31
  if (!invalidDecl) return { result: 'missing', prop }
32
32
  if (!expectedValue) return
33
33
  const { value } = invalidDecl
34
+ if (Array.isArray(expectedValue) && expectedValue.includes(value)) return
34
35
  if (value === expectedValue) return
35
36
  return { result: 'invalid', prop, invalidDecl, value, expectedValue }
36
37
  }
@@ -23,7 +23,11 @@ const messages = {
23
23
 
24
24
  module.exports = {
25
25
  ruleName: 'css-global',
26
- ruleInteraction: null,
26
+ ruleInteraction: {
27
+ 'layout-related-properties': {
28
+ childAllowDecl: decl => isCustomProperty(decl)
29
+ },
30
+ },
27
31
  cssRequirements: null,
28
32
  messages,
29
33
  create(config) {
@@ -35,6 +39,7 @@ module.exports = {
35
39
  }
36
40
 
37
41
  function isInCssGlobal(root) { return matchesFile(root, filename => filename.includes('/cssGlobal/')) }
42
+ function isCustomProperty({ prop }) { return prop.startsWith('--') }
38
43
 
39
44
  function checkAtRules({ originalRoot, report }) {
40
45
  const inCssGlobal = isInCssGlobal(originalRoot)
@@ -85,4 +85,19 @@ test('css-global', {
85
85
  },
86
86
  ],
87
87
  },
88
+ 'layout-related-properties': {
89
+ valid: [
90
+ {
91
+ title: 'valid - allow custom properties in child selectors',
92
+ code: `
93
+ .parent {
94
+ & > .child{
95
+ --x: 0;
96
+ }
97
+ }
98
+ `,
99
+ },
100
+ ],
101
+ invalid: [],
102
+ }
88
103
  })
@@ -6,7 +6,7 @@ const {
6
6
  getRootRules,
7
7
  } = require('../../machinery/ast')
8
8
  const { checkRuleRelation } = require('../../machinery/relations')
9
- const { flexChildProps, gridChildProps } = require('../../machinery/css')
9
+ const { flexChildProps, gridChildProps, flexOrGridChildProps } = require('../../machinery/css')
10
10
 
11
11
  const messages = {
12
12
  'nested - missing stacking context in parent':
@@ -21,12 +21,17 @@ const messages = {
21
21
  `missing \`display: flex;\`\n` +
22
22
  `\`${prop}\` can only be used when the containing root rule has \`display: flex;\` - ` +
23
23
  `add \`display: flex;\` to the containing root rule or, if this is caused by a media query ` +
24
- `that overrides \`display: flex;\`, use \`flex: unset\``,
24
+ `that overrides \`display: flex;\`, use \`${prop}: unset\``,
25
25
  'nested - require display grid in parent': prop =>
26
26
  `missing \`display: grid;\`\n` +
27
27
  `\`${prop}\` can only be used when the containing root rule has \`display: grid;\` - ` +
28
28
  `add \`display: grid;\` to the containing root rule or, if this is caused by a media query ` +
29
- `that overrides \`display: grid;\`, use \`grid: unset\``,
29
+ `that overrides \`display: grid;\`, use \`${prop}: unset\``,
30
+ 'nested - require display flex or grid in parent': prop =>
31
+ `missing \`display: flex;\` or \`display: grid;\`\n` +
32
+ `\`${prop}\` can only be used when the containing root rule has \`display: flex;\` or \`display: grid;\` - ` +
33
+ `add \`display: flex;\` or \`display: grid;\` to the containing root rule or, if this is caused by a media query ` +
34
+ `that overrides \`display: flex;\` or \`display: grid;\`, use \`${prop}: unset\``,
30
35
  'invalid pointer events':
31
36
  `Incorrect pointer events combination\n` +
32
37
  `you can only set pointer events in a child if the parent disables pointer events - ` +
@@ -58,18 +63,24 @@ const childParentRelations = {
58
63
  ['position', 'relative']
59
64
  ]
60
65
  },
61
- rootHasPositionFlex: {
66
+ rootHasDisplayFlex: {
62
67
  nestedHasOneOf: flexChildProps,
63
68
  requireInRoot: [
64
69
  ['display', 'flex']
65
70
  ]
66
71
  },
67
- rootHasPositionGrid: {
72
+ rootHasDisplayGrid: {
68
73
  nestedHasOneOf: gridChildProps,
69
74
  requireInRoot: [
70
75
  ['display', 'grid']
71
76
  ]
72
77
  },
78
+ rootHasDisplayFlexOrGrid: {
79
+ nestedHasOneOf: flexOrGridChildProps,
80
+ requireInRoot: [
81
+ ['display', ['flex', 'grid']]
82
+ ]
83
+ },
73
84
  validPointerEvents: {
74
85
  nestedHasOneOf: [
75
86
  ['pointer-events', 'auto']
@@ -109,6 +120,7 @@ module.exports = {
109
120
  absoluteHasRelativeParent({ root: modifiedRoot, report })
110
121
  requireDisplayFlexInParent({ root: modifiedRoot, report })
111
122
  requireDisplayGridInParent({ root: modifiedRoot, report })
123
+ requireDisplayFlexOrGridInParent({ root: modifiedRoot, report })
112
124
  validPointerEvents({ root: modifiedRoot, report })
113
125
  relativeToParent({ root: modifiedRoot, report })
114
126
  }
@@ -137,7 +149,7 @@ function absoluteHasRelativeParent({ root, report }) {
137
149
 
138
150
  function requireDisplayFlexInParent({ root, report }) {
139
151
  withNestedRules(root, (rule, parent) => {
140
- const result = checkChildParentRelation(rule, childParentRelations.rootHasPositionFlex)
152
+ const result = checkChildParentRelation(rule, childParentRelations.rootHasDisplayFlex)
141
153
 
142
154
  result.forEach(({ result, prop, triggerDecl, rootDecl, value, expectedValue }) => {
143
155
  report(triggerDecl, messages['nested - require display flex in parent'](triggerDecl.prop))
@@ -147,7 +159,7 @@ function requireDisplayFlexInParent({ root, report }) {
147
159
 
148
160
  function requireDisplayGridInParent({ root, report }) {
149
161
  withNestedRules(root, (rule, parent) => {
150
- const result = checkChildParentRelation(rule, childParentRelations.rootHasPositionGrid)
162
+ const result = checkChildParentRelation(rule, childParentRelations.rootHasDisplayGrid)
151
163
 
152
164
  result.forEach(({ result, prop, triggerDecl, rootDecl, value, expectedValue }) => {
153
165
  report(triggerDecl, messages['nested - require display grid in parent'](triggerDecl.prop))
@@ -155,6 +167,16 @@ function requireDisplayGridInParent({ root, report }) {
155
167
  })
156
168
  }
157
169
 
170
+ function requireDisplayFlexOrGridInParent({ root, report }) {
171
+ withNestedRules(root, (rule, parent) => {
172
+ const result = checkChildParentRelation(rule, childParentRelations.rootHasDisplayFlexOrGrid)
173
+
174
+ result.forEach(({ result, prop, triggerDecl, rootDecl, value, expectedValue }) => {
175
+ report(triggerDecl, messages['nested - require display flex or grid in parent'](triggerDecl.prop))
176
+ })
177
+ })
178
+ }
179
+
158
180
  function validPointerEvents({ root, report }) {
159
181
  withNestedRules(root, (rule, parent) => {
160
182
  const result = checkChildParentRelation(rule, childParentRelations.validPointerEvents)
@@ -29,7 +29,7 @@ test('parent-child-policy', {
29
29
  display: grid;
30
30
 
31
31
  & > .test {
32
- grid: 0; grid-area: 0; grid-column: 0; grid-row: 0;
32
+ grid: 0; grid-area: 0; grid-column: 0; grid-row: 0; order: 0;
33
33
  grid-column-start: 0; grid-column-end: 0; grid-row-start: 0; grid-row-end: 0;
34
34
  }
35
35
  }
@@ -207,12 +207,12 @@ test('parent-child-policy', {
207
207
  code: `
208
208
  .bad {
209
209
  & > .test {
210
- flex: 0; flex-grow: 0; flex-shrink: 0; flex-basis: 0; order: 0;
210
+ flex: 0; flex-grow: 0; flex-shrink: 0; flex-basis: 0;
211
211
  }
212
212
  }
213
213
  `,
214
214
  warnings: createMessages('nested - require display flex in parent', [
215
- 'flex', 'flex-grow', 'flex-shrink', 'flex-basis', 'order'
215
+ 'flex', 'flex-grow', 'flex-shrink', 'flex-basis',
216
216
  ])
217
217
  },
218
218
  {
@@ -221,13 +221,13 @@ test('parent-child-policy', {
221
221
  .bad {
222
222
  & > .test {
223
223
  @media x {
224
- flex: 0; flex-grow: 0; flex-shrink: 0; flex-basis: 0; order: 0;
224
+ flex: 0; flex-grow: 0; flex-shrink: 0; flex-basis: 0;
225
225
  }
226
226
  }
227
227
  }
228
228
  `,
229
229
  warnings: createMessages('nested - require display flex in parent', [
230
- 'flex', 'flex-grow', 'flex-shrink', 'flex-basis', 'order'
230
+ 'flex', 'flex-grow', 'flex-shrink', 'flex-basis',
231
231
  ])
232
232
  },
233
233
  {
@@ -300,6 +300,20 @@ test('parent-child-policy', {
300
300
  `,
301
301
  warnings: [messages['nested - require display flex in parent']('flex')]
302
302
  },
303
+ {
304
+ title: 'report missing flex or grid',
305
+ code: `.bad { & > .test { order: 0; } }`,
306
+ warnings: createMessages('nested - require display flex or grid in parent', [
307
+ 'order'
308
+ ])
309
+ },
310
+ {
311
+ title: '└─ take @media into account',
312
+ code: `.bad { & > .test { @media x { order: 0; } } }`,
313
+ warnings: createMessages('nested - require display flex or grid in parent', [
314
+ 'order'
315
+ ])
316
+ },
303
317
  ]
304
318
  },
305
319
  'layout-related-properties': {