@atlaskit/eslint-plugin-design-system 13.16.1 → 13.17.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 13.17.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#161015](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/161015)
8
+ [`c15d225be602e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c15d225be602e) -
9
+ Adds a `enableAutoFixer` flag in the no-utility-rule config to allow more flexibility for
10
+ developers.
11
+
3
12
  ## 13.16.1
4
13
 
5
14
  ### Patch Changes
@@ -20,6 +20,19 @@ var createChecks = exports.createChecks = function createChecks(context) {
20
20
  var importStatementsCore = {};
21
21
  var newButtonImports = new Set();
22
22
  var errors = {};
23
+
24
+ /**
25
+ * Gets the value of a boolean configuration flag
26
+ * @param key the key of the configuration flag
27
+ * @param defaultValue The default value of the configuration flag
28
+ * @returns defaultValue if the configuration flag is not set, the defaultValue of the configuration flag otherwise
29
+ */
30
+ var getConfigFlag = function getConfigFlag(key, defaultValue) {
31
+ if (context.options && context.options.length > 0 && context.options[0] && context.options[0].hasOwnProperty(key)) {
32
+ return context.options[0][key] === !defaultValue ? !defaultValue : defaultValue;
33
+ }
34
+ return defaultValue;
35
+ };
23
36
  var checkImportDeclarations = function checkImportDeclarations(node) {
24
37
  var moduleSource = node.source.value;
25
38
  if (typeof moduleSource !== 'string') {
@@ -134,6 +147,7 @@ var createChecks = exports.createChecks = function createChecks(context) {
134
147
  * Throws the relevant errors in the correct order.
135
148
  */
136
149
  var throwErrors = function throwErrors() {
150
+ var shouldAutoFix = getConfigFlag('enableAutoFixer', false);
137
151
  var _loop = function _loop() {
138
152
  var utilityIcon = _Object$keys[_i];
139
153
  var allFixable = errors[utilityIcon].every(function (x) {
@@ -152,7 +166,7 @@ var createChecks = exports.createChecks = function createChecks(context) {
152
166
  var _step4$value = (0, _slicedToArray2.default)(_step4.value, 2),
153
167
  index = _step4$value[0],
154
168
  error = _step4$value[1];
155
- if (error.fixable) {
169
+ if (error.fixable && shouldAutoFix) {
156
170
  context.report({
157
171
  node: error.node,
158
172
  messageId: error.messageId,
@@ -172,7 +186,7 @@ var createChecks = exports.createChecks = function createChecks(context) {
172
186
  fixes.push(fixer.replaceText(error.node, wrappedIcon));
173
187
  } else if ((0, _eslintCodemodUtils.isNodeOfType)(error.node, 'JSXElement') && (0, _eslintCodemodUtils.isNodeOfType)(error.node.openingElement.name, 'JSXIdentifier')) {
174
188
  // Replace the JSX element's closing tag with size="small"
175
- var newOpeningElementText = context.sourceCode.getText(error.node.openingElement).replace(/\s*\/\s*>$/, " size=\"small\"/>").replace(new RegExp('<\s*' + error.node.openingElement.name.name), "<".concat(replacementImportName));
189
+ var newOpeningElementText = context.sourceCode.getText(error.node.openingElement).replace(/\s*\/\s*>$/, " size=\"small\"/>").replace(new RegExp('<s*' + error.node.openingElement.name.name), "<".concat(replacementImportName));
176
190
  fixes.push(fixer.replaceText(error.node.openingElement, newOpeningElementText));
177
191
  }
178
192
 
@@ -12,6 +12,15 @@ var rule = (0, _createRule.createLintRule)({
12
12
  fixable: 'code',
13
13
  hasSuggestions: true,
14
14
  type: 'problem',
15
+ schema: [{
16
+ type: 'object',
17
+ properties: {
18
+ enableAutoFixer: {
19
+ type: 'boolean'
20
+ }
21
+ },
22
+ additionalProperties: false
23
+ }],
15
24
  docs: {
16
25
  description: 'Disallow use of deprecated utility icons, in favor of core icons with `size="small"`.',
17
26
  recommended: true,
@@ -9,6 +9,19 @@ export const createChecks = context => {
9
9
  const importStatementsCore = {};
10
10
  const newButtonImports = new Set();
11
11
  const errors = {};
12
+
13
+ /**
14
+ * Gets the value of a boolean configuration flag
15
+ * @param key the key of the configuration flag
16
+ * @param defaultValue The default value of the configuration flag
17
+ * @returns defaultValue if the configuration flag is not set, the defaultValue of the configuration flag otherwise
18
+ */
19
+ const getConfigFlag = (key, defaultValue) => {
20
+ if (context.options && context.options.length > 0 && context.options[0] && context.options[0].hasOwnProperty(key)) {
21
+ return context.options[0][key] === !defaultValue ? !defaultValue : defaultValue;
22
+ }
23
+ return defaultValue;
24
+ };
12
25
  const checkImportDeclarations = node => {
13
26
  const moduleSource = node.source.value;
14
27
  if (typeof moduleSource !== 'string') {
@@ -96,6 +109,7 @@ export const createChecks = context => {
96
109
  * Throws the relevant errors in the correct order.
97
110
  */
98
111
  const throwErrors = () => {
112
+ const shouldAutoFix = getConfigFlag('enableAutoFixer', false);
99
113
  for (const utilityIcon of Object.keys(errors)) {
100
114
  const allFixable = errors[utilityIcon].every(x => x.fixable); // Check if ALL errors for a giving import are fixable
101
115
  const originalImportNode = importStatementsUtility[utilityIcon];
@@ -105,7 +119,7 @@ export const createChecks = context => {
105
119
  let replacementImportName = existingImport ? existingImport : allFixable ? utilityIcon : `${utilityIcon}Core`;
106
120
  let importFixAdded = false;
107
121
  for (const [index, error] of errors[utilityIcon].entries()) {
108
- if (error.fixable) {
122
+ if (error.fixable && shouldAutoFix) {
109
123
  context.report({
110
124
  node: error.node,
111
125
  messageId: error.messageId,
@@ -125,7 +139,7 @@ export const createChecks = context => {
125
139
  fixes.push(fixer.replaceText(error.node, wrappedIcon));
126
140
  } else if (isNodeOfType(error.node, 'JSXElement') && isNodeOfType(error.node.openingElement.name, 'JSXIdentifier')) {
127
141
  // Replace the JSX element's closing tag with size="small"
128
- const newOpeningElementText = context.sourceCode.getText(error.node.openingElement).replace(/\s*\/\s*>$/, ` size="small"\/>`).replace(new RegExp('<\s*' + error.node.openingElement.name.name), `<${replacementImportName}`);
142
+ const newOpeningElementText = context.sourceCode.getText(error.node.openingElement).replace(/\s*\/\s*>$/, ` size="small"\/>`).replace(new RegExp('<s*' + error.node.openingElement.name.name), `<${replacementImportName}`);
129
143
  fixes.push(fixer.replaceText(error.node.openingElement, newOpeningElementText));
130
144
  }
131
145
 
@@ -6,6 +6,15 @@ const rule = createLintRule({
6
6
  fixable: 'code',
7
7
  hasSuggestions: true,
8
8
  type: 'problem',
9
+ schema: [{
10
+ type: 'object',
11
+ properties: {
12
+ enableAutoFixer: {
13
+ type: 'boolean'
14
+ }
15
+ },
16
+ additionalProperties: false
17
+ }],
9
18
  docs: {
10
19
  description: 'Disallow use of deprecated utility icons, in favor of core icons with `size="small"`.',
11
20
  recommended: true,
@@ -13,6 +13,19 @@ export var createChecks = function createChecks(context) {
13
13
  var importStatementsCore = {};
14
14
  var newButtonImports = new Set();
15
15
  var errors = {};
16
+
17
+ /**
18
+ * Gets the value of a boolean configuration flag
19
+ * @param key the key of the configuration flag
20
+ * @param defaultValue The default value of the configuration flag
21
+ * @returns defaultValue if the configuration flag is not set, the defaultValue of the configuration flag otherwise
22
+ */
23
+ var getConfigFlag = function getConfigFlag(key, defaultValue) {
24
+ if (context.options && context.options.length > 0 && context.options[0] && context.options[0].hasOwnProperty(key)) {
25
+ return context.options[0][key] === !defaultValue ? !defaultValue : defaultValue;
26
+ }
27
+ return defaultValue;
28
+ };
16
29
  var checkImportDeclarations = function checkImportDeclarations(node) {
17
30
  var moduleSource = node.source.value;
18
31
  if (typeof moduleSource !== 'string') {
@@ -127,6 +140,7 @@ export var createChecks = function createChecks(context) {
127
140
  * Throws the relevant errors in the correct order.
128
141
  */
129
142
  var throwErrors = function throwErrors() {
143
+ var shouldAutoFix = getConfigFlag('enableAutoFixer', false);
130
144
  var _loop = function _loop() {
131
145
  var utilityIcon = _Object$keys[_i];
132
146
  var allFixable = errors[utilityIcon].every(function (x) {
@@ -145,7 +159,7 @@ export var createChecks = function createChecks(context) {
145
159
  var _step4$value = _slicedToArray(_step4.value, 2),
146
160
  index = _step4$value[0],
147
161
  error = _step4$value[1];
148
- if (error.fixable) {
162
+ if (error.fixable && shouldAutoFix) {
149
163
  context.report({
150
164
  node: error.node,
151
165
  messageId: error.messageId,
@@ -165,7 +179,7 @@ export var createChecks = function createChecks(context) {
165
179
  fixes.push(fixer.replaceText(error.node, wrappedIcon));
166
180
  } else if (isNodeOfType(error.node, 'JSXElement') && isNodeOfType(error.node.openingElement.name, 'JSXIdentifier')) {
167
181
  // Replace the JSX element's closing tag with size="small"
168
- var newOpeningElementText = context.sourceCode.getText(error.node.openingElement).replace(/\s*\/\s*>$/, " size=\"small\"/>").replace(new RegExp('<\s*' + error.node.openingElement.name.name), "<".concat(replacementImportName));
182
+ var newOpeningElementText = context.sourceCode.getText(error.node.openingElement).replace(/\s*\/\s*>$/, " size=\"small\"/>").replace(new RegExp('<s*' + error.node.openingElement.name.name), "<".concat(replacementImportName));
169
183
  fixes.push(fixer.replaceText(error.node.openingElement, newOpeningElementText));
170
184
  }
171
185
 
@@ -6,6 +6,15 @@ var rule = createLintRule({
6
6
  fixable: 'code',
7
7
  hasSuggestions: true,
8
8
  type: 'problem',
9
+ schema: [{
10
+ type: 'object',
11
+ properties: {
12
+ enableAutoFixer: {
13
+ type: 'boolean'
14
+ }
15
+ },
16
+ additionalProperties: false
17
+ }],
9
18
  docs: {
10
19
  description: 'Disallow use of deprecated utility icons, in favor of core icons with `size="small"`.',
11
20
  recommended: true,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
3
  "description": "The essential plugin for use with the Atlassian Design System.",
4
- "version": "13.16.1",
4
+ "version": "13.17.0",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
7
7
  "publishConfig": {
@@ -44,8 +44,8 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@atlaskit/eslint-utils": "^2.0.0",
47
- "@atlaskit/icon": "^26.1.0",
48
- "@atlaskit/icon-lab": "^4.13.0",
47
+ "@atlaskit/icon": "^26.3.0",
48
+ "@atlaskit/icon-lab": "^4.16.0",
49
49
  "@atlaskit/tokens": "^4.9.0",
50
50
  "@babel/runtime": "^7.0.0",
51
51
  "@typescript-eslint/utils": "^7.1.0",