File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ const config = {
10
10
rules : {
11
11
'@liferay/portal/deprecation' : 'error' ,
12
12
'@liferay/portal/empty-line-after-copyright' : 'error' ,
13
+ '@liferay/portal/no-api-submodule-import' : 'error' ,
13
14
'@liferay/portal/no-default-export-from-frontend-js-web' : 'error' ,
14
15
'@liferay/portal/no-document-cookie' : 'error' ,
15
16
'@liferay/portal/no-explicit-extend' : 'error' ,
Original file line number Diff line number Diff line change 6
6
module . exports = {
7
7
'portal/deprecation' : require ( './lib/rules/deprecation' ) ,
8
8
'portal/empty-line-after-copyright' : require ( './lib/rules/empty-line-after-copyright' ) ,
9
+ 'portal/no-api-submodule-import' : require ( './lib/rules/no-api-submodule-import' ) ,
9
10
'portal/no-default-export-from-frontend-js-web' : require ( './lib/rules/no-default-export-from-frontend-js-web' ) ,
10
11
'portal/no-document-cookie' : require ( './lib/rules/no-document-cookie' ) ,
11
12
'portal/no-explicit-extend' : require ( './lib/rules/no-explicit-extend' ) ,
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 path = require ( 'path' ) ;
7
+
8
+ const DESCRIPTION =
9
+ 'you cannot import files outside of the "/api" directory for your submodule.' ;
10
+
11
+ const API_PATH = 'src/main/resources/META-INF/resources/js/api' ;
12
+
13
+ function isPathEscapingAPIDir ( filePath , relativePath ) {
14
+ const resolvedTarget = path . resolve ( path . dirname ( filePath ) , relativePath ) ;
15
+
16
+ return ! resolvedTarget . includes ( API_PATH ) ;
17
+ }
18
+
19
+ function checkImportPath ( node , context ) {
20
+ if (
21
+ context . getFilename ( ) . includes ( API_PATH ) &&
22
+ node . source &&
23
+ node . source . type === 'Literal' &&
24
+ node . source . value . startsWith ( '.' )
25
+ ) {
26
+ if ( isPathEscapingAPIDir ( context . getFilename ( ) , node . source . value ) ) {
27
+ context . report ( {
28
+ message : DESCRIPTION ,
29
+ node,
30
+ } ) ;
31
+ }
32
+ }
33
+ }
34
+
35
+ module . exports = {
36
+ create ( context ) {
37
+ return {
38
+ ExportDefaultDeclaration ( node ) {
39
+ checkImportPath ( node , context ) ;
40
+ } ,
41
+ ExportNamedDeclaration ( node ) {
42
+ checkImportPath ( node , context ) ;
43
+ } ,
44
+ ImportDeclaration ( node ) {
45
+ checkImportPath ( node , context ) ;
46
+ } ,
47
+ } ;
48
+ } ,
49
+
50
+ meta : {
51
+ docs : {
52
+ category : 'Best Practices' ,
53
+ description : DESCRIPTION ,
54
+ recommended : false ,
55
+ } ,
56
+ fixable : null ,
57
+ schema : [ ] ,
58
+ type : 'problem' ,
59
+ } ,
60
+ } ;
You can’t perform that action at this time.
0 commit comments