eslint-plugin-formatjs
Advanced tools
| import { Rule } from 'eslint'; | ||
| declare const rule: Rule.RuleModule; | ||
| export default rule; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const util_1 = require("../util"); | ||
| function checkNode(context, node, importedMacroVars) { | ||
| const msgs = util_1.extractMessages(node, importedMacroVars); | ||
| for (const [{ message: { defaultMessage }, messageNode, },] of msgs) { | ||
| if (!defaultMessage && !messageNode) { | ||
| context.report({ | ||
| node, | ||
| message: '`defaultMessage` has to be specified in message descriptor', | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| const rule = { | ||
| meta: { | ||
| type: 'problem', | ||
| docs: { | ||
| description: 'Enforce defaultMessage in message descriptor', | ||
| category: 'Errors', | ||
| recommended: false, | ||
| url: 'https://github.com/formatjs/formatjs/tree/master/packages/eslint-plugin-formatjs#enforce-default-message', | ||
| }, | ||
| fixable: 'code', | ||
| }, | ||
| create(context) { | ||
| let importedMacroVars = []; | ||
| return { | ||
| ImportDeclaration: node => { | ||
| const moduleName = node.source.value; | ||
| if (moduleName === '@formatjs/macro' || moduleName === 'react-intl') { | ||
| importedMacroVars = context.getDeclaredVariables(node); | ||
| } | ||
| }, | ||
| JSXOpeningElement: (node) => checkNode(context, node, importedMacroVars), | ||
| CallExpression: node => checkNode(context, node, importedMacroVars), | ||
| }; | ||
| }, | ||
| }; | ||
| exports.default = rule; | ||
| //# sourceMappingURL=enforce-default-message.js.map |
| {"version":3,"file":"enforce-default-message.js","sourceRoot":"","sources":["../../src/rules/enforce-default-message.ts"],"names":[],"mappings":";;AAEA,kCAAwC;AAExC,SAAS,SAAS,CAChB,OAAyB,EACzB,IAAU,EACV,iBAAmC;IAEnC,MAAM,IAAI,GAAG,sBAAe,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;IACtD,KAAK,MAAM,CACT,EACE,OAAO,EAAE,EAAC,cAAc,EAAC,EACzB,WAAW,GACZ,EACF,IAAI,IAAI,EAAE;QACT,IAAI,CAAC,cAAc,IAAI,CAAC,WAAW,EAAE;YACnC,OAAO,CAAC,MAAM,CAAC;gBACb,IAAI;gBACJ,OAAO,EAAE,4DAA4D;aACtE,CAAC,CAAC;SACJ;KACF;AACH,CAAC;AAED,MAAM,IAAI,GAAoB;IAC5B,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,8CAA8C;YAC3D,QAAQ,EAAE,QAAQ;YAClB,WAAW,EAAE,KAAK;YAClB,GAAG,EACD,0GAA0G;SAC7G;QACD,OAAO,EAAE,MAAM;KAChB;IACD,MAAM,CAAC,OAAO;QACZ,IAAI,iBAAiB,GAAqB,EAAE,CAAC;QAC7C,OAAO;YACL,iBAAiB,EAAE,IAAI,CAAC,EAAE;gBACxB,MAAM,UAAU,GAAI,IAA0B,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC5D,IAAI,UAAU,KAAK,iBAAiB,IAAI,UAAU,KAAK,YAAY,EAAE;oBACnE,iBAAiB,GAAG,OAAO,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;iBACxD;YACH,CAAC;YACD,iBAAiB,EAAE,CAAC,IAAU,EAAE,EAAE,CAChC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,iBAAiB,CAAC;YAC7C,cAAc,EAAE,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,iBAAiB,CAAC;SACpE,CAAC;IACJ,CAAC;CACF,CAAC;AAEF,kBAAe,IAAI,CAAC"} |
| import {Rule, Scope} from 'eslint'; | ||
| import {ImportDeclaration, Node} from 'estree'; | ||
| import {extractMessages} from '../util'; | ||
| function checkNode( | ||
| context: Rule.RuleContext, | ||
| node: Node, | ||
| importedMacroVars: Scope.Variable[] | ||
| ) { | ||
| const msgs = extractMessages(node, importedMacroVars); | ||
| for (const [ | ||
| { | ||
| message: {defaultMessage}, | ||
| messageNode, | ||
| }, | ||
| ] of msgs) { | ||
| if (!defaultMessage && !messageNode) { | ||
| context.report({ | ||
| node, | ||
| message: '`defaultMessage` has to be specified in message descriptor', | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| const rule: Rule.RuleModule = { | ||
| meta: { | ||
| type: 'problem', | ||
| docs: { | ||
| description: 'Enforce defaultMessage in message descriptor', | ||
| category: 'Errors', | ||
| recommended: false, | ||
| url: | ||
| 'https://github.com/formatjs/formatjs/tree/master/packages/eslint-plugin-formatjs#enforce-default-message', | ||
| }, | ||
| fixable: 'code', | ||
| }, | ||
| create(context) { | ||
| let importedMacroVars: Scope.Variable[] = []; | ||
| return { | ||
| ImportDeclaration: node => { | ||
| const moduleName = (node as ImportDeclaration).source.value; | ||
| if (moduleName === '@formatjs/macro' || moduleName === 'react-intl') { | ||
| importedMacroVars = context.getDeclaredVariables(node); | ||
| } | ||
| }, | ||
| JSXOpeningElement: (node: Node) => | ||
| checkNode(context, node, importedMacroVars), | ||
| CallExpression: node => checkNode(context, node, importedMacroVars), | ||
| }; | ||
| }, | ||
| }; | ||
| export default rule; |
+11
-0
@@ -6,2 +6,13 @@ # Change Log | ||
| # [1.6.0](https://github.com/formatjs/formatjs/compare/eslint-plugin-formatjs@1.5.11...eslint-plugin-formatjs@1.6.0) (2020-03-01) | ||
| ### Features | ||
| * **eslint-plugin-formatjs:** add support for defaultMessage ([#524](https://github.com/formatjs/formatjs/issues/524)) ([63742d6](https://github.com/formatjs/formatjs/commit/63742d697732f2e88176c8f310f89bf65c2f9576)) | ||
| ## [1.5.11](https://github.com/formatjs/formatjs/compare/eslint-plugin-formatjs@1.5.10...eslint-plugin-formatjs@1.5.11) (2020-01-27) | ||
@@ -8,0 +19,0 @@ |
+1
-0
| declare const plugin: { | ||
| rules: { | ||
| 'enforce-description': import("eslint").Rule.RuleModule; | ||
| 'enforce-default-message': import("eslint").Rule.RuleModule; | ||
| 'no-camel-case': import("eslint").Rule.RuleModule; | ||
@@ -5,0 +6,0 @@ 'no-emoji': import("eslint").Rule.RuleModule; |
+2
-0
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const enforce_description_1 = require("./rules/enforce-description"); | ||
| const enforce_default_message_1 = require("./rules/enforce-default-message"); | ||
| const no_camel_case_1 = require("./rules/no-camel-case"); | ||
@@ -15,2 +16,3 @@ const no_emoji_1 = require("./rules/no-emoji"); | ||
| 'enforce-description': enforce_description_1.default, | ||
| 'enforce-default-message': enforce_default_message_1.default, | ||
| 'no-camel-case': no_camel_case_1.default, | ||
@@ -17,0 +19,0 @@ 'no-emoji': no_emoji_1.default, |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,qEAA6D;AAC7D,yDAAgD;AAChD,+CAAuC;AACvC,qEAA4D;AAC5D,iDAAyC;AACzC,mEAA2D;AAC3D,uEAA8D;AAC9D,uEAA+D;AAC/D,qFAAmF;AACnF,MAAM,MAAM,GAAG;IACb,KAAK,EAAE;QACL,qBAAqB,EAAE,6BAAkB;QACzC,eAAe,EAAE,uBAAW;QAC5B,UAAU,EAAE,kBAAO;QACnB,qBAAqB,EAAE,6BAAiB;QACxC,WAAW,EAAE,mBAAQ;QACrB,oBAAoB,EAAE,4BAAiB;QACvC,sBAAsB,EAAE,8BAAkB;QAC1C,sBAAsB,EAAE,8BAAmB;QAC3C,6BAA6B,EAAE,qCAAgC;KAChE;CACF,CAAC;AAIF,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC"} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,qEAA6D;AAC7D,6EAAoE;AACpE,yDAAgD;AAChD,+CAAuC;AACvC,qEAA4D;AAC5D,iDAAyC;AACzC,mEAA2D;AAC3D,uEAA8D;AAC9D,uEAA+D;AAC/D,qFAAmF;AACnF,MAAM,MAAM,GAAG;IACb,KAAK,EAAE;QACL,qBAAqB,EAAE,6BAAkB;QACzC,yBAAyB,EAAE,iCAAqB;QAChD,eAAe,EAAE,uBAAW;QAC5B,UAAU,EAAE,kBAAO;QACnB,qBAAqB,EAAE,6BAAiB;QACxC,WAAW,EAAE,mBAAQ;QACrB,oBAAoB,EAAE,4BAAiB;QACvC,sBAAsB,EAAE,8BAAkB;QAC1C,sBAAsB,EAAE,8BAAmB;QAC3C,6BAA6B,EAAE,qCAAgC;KAChE;CACF,CAAC;AAIF,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC"} |
+3
-2
| { | ||
| "name": "eslint-plugin-formatjs", | ||
| "version": "1.5.11", | ||
| "version": "1.6.0", | ||
| "description": "ESLint plugin for formatjs", | ||
@@ -37,3 +37,4 @@ "main": "dist/index.js", | ||
| "eslint": "^6.0.0" | ||
| } | ||
| }, | ||
| "gitHead": "f7f8ddb5ba81afbe04e7da8f438e08662096ae11" | ||
| } |
+24
-0
@@ -126,2 +126,26 @@ # eslint-plugin-formatjs | ||
| ### `enforce-default-message` | ||
| This enforces `defaultMessage` in the message descriptor. | ||
| #### Why | ||
| - Can be usefull in case we want to extract messages for translations from source code. This way can make sure people won't forget about defaultMessage | ||
| ```tsx | ||
| import {defineMessages} from 'react-intl'; | ||
| const messages = defineMessages({ | ||
| // WORKS | ||
| foo: { | ||
| defaultMessage: 'This is default message', | ||
| description: 'bar', | ||
| }, | ||
| // FAILS | ||
| bar: { | ||
| description: 'bar', | ||
| }, | ||
| }); | ||
| ``` | ||
| ### `enforce-placeholders` | ||
@@ -128,0 +152,0 @@ |
+2
-0
| import enforceDescription from './rules/enforce-description'; | ||
| import enforceDefaultMessage from './rules/enforce-default-message'; | ||
| import noCamelCase from './rules/no-camel-case'; | ||
@@ -13,2 +14,3 @@ import noEmoji from './rules/no-emoji'; | ||
| 'enforce-description': enforceDescription, | ||
| 'enforce-default-message': enforceDefaultMessage, | ||
| 'no-camel-case': noCamelCase, | ||
@@ -15,0 +17,0 @@ 'no-emoji': noEmoji, |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
103099
5.7%52
8.33%1983
5.25%339
7.62%0
-100%