File tree Expand file tree Collapse file tree 10 files changed +316
-2
lines changed
maintenance/projects/senna
js-toolkit/packages/dev-server/src Expand file tree Collapse file tree 10 files changed +316
-2
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ module.exports = {
1212 rules : {
1313 '@liferay/no-abbreviations' : 'off' ,
1414 '@liferay/no-it-should' : 'warn' ,
15+ '@liferay/no-use-strict-in-module' : 'off' ,
1516 'curly' : 'warn' ,
1617 'default-case' : 'warn' ,
1718 'no-console' : 'warn' ,
Original file line number Diff line number Diff line change @@ -101,12 +101,14 @@ const config = {
101101 '@liferay/imports-first' : 'error' ,
102102 '@liferay/no-abbreviations' : 'error' ,
103103 '@liferay/no-absolute-import' : 'error' ,
104+ '@liferay/no-anonymous-exports' : 'error' ,
104105 '@liferay/no-duplicate-imports' : 'error' ,
105106 '@liferay/no-dynamic-require' : 'error' ,
106107 '@liferay/no-get-data-attribute' : 'error' ,
107108 '@liferay/no-it-should' : 'error' ,
108109 '@liferay/no-length-jsx-expression' : 'error' ,
109110 '@liferay/no-require-and-call' : 'error' ,
111+ '@liferay/no-use-strict-in-module' : 'error' ,
110112 '@liferay/padded-test-blocks' : 'error' ,
111113 '@liferay/ref-name-suffix' : 'error' ,
112114 '@liferay/sort-import-destructures' : 'error' ,
Original file line number Diff line number Diff line change 1+ # Prefer exporting named functions (no-anonymous-exports)
2+
3+ To improve debugging and readability, it is preferable to export named functions to that they can be located in a callstack.
4+
5+ ## Rule Details
6+
7+ Examples of ** incorrect** code for this rule:
8+
9+ ``` js
10+ export const x = () => {};
11+
12+ export default () => {};
13+ ```
14+
15+ Examples of ** correct** code for this rule:
16+
17+ ``` js
18+ export function x () {}
19+
20+ export default function x () {}
21+ ```
22+
23+ ## See also
24+
25+ - https://github.com/liferay/liferay-frontend-projects/issues/25
Original file line number Diff line number Diff line change 1+ # Disallow 'use strict' in es modules (no-use-strict-in-module)
2+
3+ You never need ` 'use strict' ` in an ES module ([ spec] ( http://www.ecma-international.org/ecma-262/6.0/#sec-strict-mode-code ) ). We can infer if file is an esmodule if it uses export/import syntax.
4+
5+ ## Rule Details
6+
7+ Examples of ** incorrect** code for this rule:
8+
9+ ``` js
10+ ' use strict' ;
11+
12+ export default () => {};
13+ ```
14+
15+ ``` js
16+ ' use strict' ;
17+
18+ import foo from ' bar' ;
19+ ```
20+
21+ Examples of ** correct** code for this rule:
22+
23+ ``` js
24+ import foo from ' bar' ;
25+ // ...
26+ ```
27+
28+ ``` js
29+ // ...
30+ export default foo ;
31+ ```
32+
33+ ``` js
34+ // ...
35+ export foo ;
36+ ```
37+
38+ ## Further Reading
39+
40+ - [ Initial motivation for this rule] ( https://github.com/liferay/liferay-frontend-projects/issues/20 ) .
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ module.exports = {
1313 'imports-first' : require ( './lib/rules/imports-first' ) ,
1414 'no-abbreviations' : require ( './lib/rules/no-abbreviations' ) ,
1515 'no-absolute-import' : require ( './lib/rules/no-absolute-import' ) ,
16+ 'no-anonymous-exports' : require ( './lib/rules/no-anonymous-exports' ) ,
1617 'no-arrow' : require ( './lib/rules/no-arrow' ) ,
1718 'no-duplicate-class-names' : require ( './lib/rules/no-duplicate-class-names' ) ,
1819 'no-duplicate-imports' : require ( './lib/rules/no-duplicate-imports' ) ,
@@ -21,6 +22,7 @@ module.exports = {
2122 'no-it-should' : require ( './lib/rules/no-it-should' ) ,
2223 'no-length-jsx-expression' : require ( './lib/rules/no-length-jsx-expression' ) ,
2324 'no-require-and-call' : require ( './lib/rules/no-require-and-call' ) ,
25+ 'no-use-strict-in-module' : require ( './lib/rules/no-use-strict-in-module' ) ,
2426 'padded-test-blocks' : require ( './lib/rules/padded-test-blocks' ) ,
2527 'ref-name-suffix' : require ( './lib/rules/ref-name-suffix' ) ,
2628 'sort-class-names' : require ( './lib/rules/sort-class-names' ) ,
Original file line number Diff line number Diff line change 1+ /**
2+ * SPDX-FileCopyrightText: © 2021 Liferay, Inc. <https://liferay.com>
3+ * SPDX-License-Identifier: MIT
4+ */
5+
6+ module . exports = {
7+ create ( context ) {
8+ return {
9+ ExportDefaultDeclaration ( node ) {
10+ if (
11+ node . declaration &&
12+ node . declaration . type === 'ArrowFunctionExpression'
13+ ) {
14+ context . report ( {
15+ message :
16+ "Use named function for export. Example: 'function fooBar() {}'" ,
17+ node,
18+ } ) ;
19+ }
20+ } ,
21+ ExportNamedDeclaration ( node ) {
22+ if (
23+ node . declaration &&
24+ node . declaration . type === 'VariableDeclaration' &&
25+ node . declaration . declarations &&
26+ node . declaration . declarations [ 0 ] &&
27+ node . declaration . declarations [ 0 ] . init &&
28+ node . declaration . declarations [ 0 ] . init . type ===
29+ 'ArrowFunctionExpression'
30+ ) {
31+ context . report ( {
32+ message :
33+ "Use named function for export instead of arrow function. Example: 'function fooBar() {}'" ,
34+ node,
35+ } ) ;
36+ }
37+ } ,
38+ } ;
39+ } ,
40+ meta : {
41+ category : 'Best Practices' ,
42+ description : 'Prefer exporting named functions' ,
43+ recommended : false ,
44+ url : 'https://github.com/liferay/liferay-frontend-projects/issues/25' ,
45+ } ,
46+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * SPDX-FileCopyrightText: © 2021 Liferay, Inc. <https://liferay.com>
3+ * SPDX-License-Identifier: MIT
4+ */
5+
6+ const message = `'use strict' is unnecessary inside of modules` ;
7+
8+ module . exports = {
9+ create ( context ) {
10+ const useStrictExpressions = [ ] ;
11+ let esModule ;
12+
13+ const checkEsModule = ( ) => {
14+ if ( ! esModule ) {
15+ esModule = true ;
16+ }
17+ } ;
18+
19+ return {
20+ 'ExportDefaultDeclaration' : checkEsModule ,
21+ 'ExportNamedDeclaration' : checkEsModule ,
22+ 'ExpressionStatement' ( node ) {
23+ if (
24+ node . expression . type === 'Literal' &&
25+ node . expression . value === 'use strict'
26+ ) {
27+ useStrictExpressions . push ( node . expression ) ;
28+ }
29+ } ,
30+ 'ImportDeclaration' : checkEsModule ,
31+ 'ImportNamespaceSpecifier' : checkEsModule ,
32+ 'Program:exit' : ( ) => {
33+ if ( esModule ) {
34+ useStrictExpressions . forEach ( ( expression ) => {
35+ context . report ( {
36+ message,
37+ node : expression ,
38+ } ) ;
39+ } ) ;
40+ }
41+ } ,
42+ } ;
43+ } ,
44+
45+ meta : {
46+ docs : {
47+ category : 'Best Practices' ,
48+ description : message ,
49+ recommended : false ,
50+ url :
51+ 'https://github.com/liferay/liferay-frontend-projects/issues/20' ,
52+ } ,
53+ fixable : 'code' ,
54+ schema : [ ] ,
55+ type : 'problem' ,
56+ } ,
57+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * SPDX-FileCopyrightText: © 2017 Liferay, Inc. <https://liferay.com>
3+ * SPDX-License-Identifier: MIT
4+ */
5+
6+ const MultiTester = require ( '../../../../../scripts/MultiTester' ) ;
7+ const rule = require ( '../../../lib/rules/no-anonymous-exports' ) ;
8+
9+ const parserOptions = {
10+ parserOptions : {
11+ ecmaVersion : 6 ,
12+ sourceType : 'module' ,
13+ } ,
14+ } ;
15+
16+ const ruleTester = new MultiTester ( parserOptions ) ;
17+
18+ ruleTester . run ( 'no-anonymous-exports' , rule , {
19+ invalid : [
20+ {
21+ code : `export const test = () => {}` ,
22+ errors : [
23+ {
24+ message :
25+ "Use named function for export instead of arrow function. Example: 'function fooBar() {}'" ,
26+ type : 'ExportNamedDeclaration' ,
27+ } ,
28+ ] ,
29+ } ,
30+ {
31+ code : `export default () => {}` ,
32+ errors : [
33+ {
34+ message :
35+ "Use named function for export. Example: 'function fooBar() {}'" ,
36+ type : 'ExportDefaultDeclaration' ,
37+ } ,
38+ ] ,
39+ } ,
40+ ] ,
41+ valid : [
42+ {
43+ code : `
44+ export function test() {}
45+ export default function fooBar() {}
46+ ` ,
47+ } ,
48+ ] ,
49+ } ) ;
Original file line number Diff line number Diff line change 1+ /**
2+ * SPDX-FileCopyrightText: © 2017 Liferay, Inc. <https://liferay.com>
3+ * SPDX-License-Identifier: MIT
4+ */
5+
6+ const MultiTester = require ( '../../../../../scripts/MultiTester' ) ;
7+ const rule = require ( '../../../lib/rules/no-use-strict-in-module' ) ;
8+
9+ const parserOptions = {
10+ parserOptions : {
11+ ecmaVersion : 6 ,
12+ sourceType : 'module' ,
13+ } ,
14+ } ;
15+
16+ const ruleTester = new MultiTester ( parserOptions ) ;
17+
18+ ruleTester . run ( 'no-use-strict-in-module' , rule , {
19+ invalid : [
20+ {
21+ code : `
22+ 'use strict'
23+
24+ import {test} from 'test';
25+ ` ,
26+ errors : [
27+ {
28+ message : `'use strict' is unnecessary inside of modules` ,
29+ type : 'Literal' ,
30+ } ,
31+ ] ,
32+ } ,
33+ {
34+ code : `
35+ 'use strict'
36+
37+ function test() {
38+ 'use strict'
39+
40+ return 'test';
41+ }
42+ export default test;
43+ ` ,
44+ errors : [
45+ {
46+ message : `'use strict' is unnecessary inside of modules` ,
47+ type : 'Literal' ,
48+ } ,
49+ {
50+ message : `'use strict' is unnecessary inside of modules` ,
51+ type : 'Literal' ,
52+ } ,
53+ ] ,
54+ } ,
55+ {
56+ code : `
57+ 'use strict'
58+
59+ function test() {}
60+ export {test};
61+ ` ,
62+ errors : [
63+ {
64+ message : `'use strict' is unnecessary inside of modules` ,
65+ type : 'Literal' ,
66+ } ,
67+ ] ,
68+ } ,
69+ ] ,
70+
71+ valid : [
72+ {
73+ code : `
74+ import {test} from 'test';
75+ ` ,
76+ } ,
77+ {
78+ code : `
79+ 'use strict'
80+
81+ module.export = function test() {}
82+ ` ,
83+ } ,
84+ {
85+ code : `
86+ 'use strict'
87+
88+ console.log('foo');
89+ ` ,
90+ } ,
91+ ] ,
92+ } ) ;
Original file line number Diff line number Diff line change @@ -46,9 +46,9 @@ function setupLiveSession(): void {
4646const CLOSE_BODY_TAG = '</body>' ;
4747const RELOAD_SNIPPET = `<script>(${ setupLiveSession . toString ( ) } )();</script>` ;
4848
49- export default ( content : string ) : string => {
49+ export default function ( content : string ) : string {
5050 return content . replace (
5151 CLOSE_BODY_TAG ,
5252 `${ RELOAD_SNIPPET } ${ CLOSE_BODY_TAG } `
5353 ) ;
54- } ;
54+ }
You can’t perform that action at this time.
0 commit comments