File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import nodeConfig from "./node.js";
66import packageJSON from "./package-json.js" ;
77import stylisticConfig from "./stylistic.js" ;
88import typescriptConfig from "./typescript.js" ;
9+ import webpackSpecial from "./webpack-special.js" ;
910
1011const configs = {
1112 ...browserConfig ,
@@ -16,6 +17,7 @@ const configs = {
1617 ...stylisticConfig ,
1718 ...typescriptConfig ,
1819 ...packageJSON ,
20+ ...webpackSpecial ,
1921} ;
2022
2123export default configs ;
Original file line number Diff line number Diff line change 1+ import { configs } from "../plugins/webpack/index.js" ;
2+
3+ const recommendedWebpackSpecialConfig = {
4+ ...configs . recommended ,
5+ } ;
6+
7+ export default {
8+ "webpack/special" : recommendedWebpackSpecialConfig ,
9+ } ;
Original file line number Diff line number Diff line change @@ -39,4 +39,9 @@ export default defineConfig([
3939 "n/hashbang" : "off" ,
4040 } ,
4141 } ,
42+ // For test purposes
43+ {
44+ files : [ "./validation/webpack/**/*" ] ,
45+ extends : [ configs [ "recommended-commonjs" ] , configs [ "webpack/special" ] ] ,
46+ } ,
4247] ) ;
Original file line number Diff line number Diff line change 1+ import { createRequire } from "node:module" ;
2+ import { allExtensions } from "../../configs/utils/extensions.js" ;
3+ import { rule as requireLicenseComment } from "./rules/require-license-comment.js" ;
4+
5+ const require = createRequire ( import . meta. url ) ;
6+
7+ const { version } = require ( "../../package.json" ) ;
8+
9+ const rules = {
10+ "require-license-comment" : requireLicenseComment ,
11+ } ;
12+
13+ const recommendedRules = {
14+ ...Object . fromEntries (
15+ Object . entries ( rules )
16+ . filter ( ( [ , rule ] ) => rule . meta . docs ?. recommended )
17+ . map ( ( [ name ] ) => [ `webpack/${ name } ` , "error" ] ) ,
18+ ) ,
19+ } ;
20+
21+ const configs = {
22+ recommended : {
23+ name : "webpack/recommended" ,
24+ files : [ `**/*.{${ allExtensions . map ( ( item ) => item . slice ( 1 ) ) . join ( "," ) } }` ] ,
25+ plugins : {
26+ get webpack ( ) {
27+ // eslint-disable-next-line no-use-before-define
28+ return plugin ;
29+ } ,
30+ } ,
31+ rules : recommendedRules ,
32+ } ,
33+ } ;
34+
35+ const plugin = {
36+ configs,
37+ meta : {
38+ version,
39+ } ,
40+ rules,
41+ } ;
42+
43+ export { configs , rules } ;
44+
45+ export default plugin ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @type {import("eslint").Rule } rule
3+ */
4+ export const rule = {
5+ create ( context ) {
6+ const sourceCode = context . getSourceCode ( ) ;
7+
8+ return {
9+ "Program:exit" ( program ) {
10+ const comments = sourceCode . getAllComments ( ) ;
11+ const licenseComment = comments . find (
12+ ( comment ) =>
13+ comment . type === "Block" &&
14+ / \n \s * M I T L i c e n s e h t t p : \/ \/ w w w \. o p e n s o u r c e \. o r g \/ l i c e n s e s \/ m i t - l i c e n s e \. p h p \n \s * (?: ( A u t h o r s ? .+ ) \n ) ? \s * / g. test (
15+ comment . value ,
16+ ) ,
17+ ) ;
18+
19+ if ( ! licenseComment ) {
20+ context . report ( {
21+ loc : program . loc ,
22+ message : "Expected license comment." ,
23+ } ) ;
24+
25+ return ;
26+ }
27+
28+ const afterComment = sourceCode . text [ licenseComment . end ] ;
29+
30+ if ( afterComment !== "\n" ) {
31+ context . report ( {
32+ loc : licenseComment . loc ,
33+ message : "Expected newline after license comment." ,
34+ } ) ;
35+
36+ return ;
37+ }
38+
39+ const afterAfterComment = sourceCode . text [ licenseComment . end + 1 ] ;
40+
41+ if ( afterAfterComment !== "\n" ) {
42+ context . report ( {
43+ loc : licenseComment . loc ,
44+ message : "Expected newline after license comment." ,
45+ } ) ;
46+ }
47+ } ,
48+ } ;
49+ } ,
50+ meta : {
51+ docs : {
52+ category : "Best Practices" ,
53+ description : "Require license comment" ,
54+ recommended : true ,
55+ } ,
56+ fixable : "code" ,
57+ type : "layout" ,
58+ } ,
59+ } ;
Original file line number Diff line number Diff line change 1+ /*
2+ MIT License http://www.opensource.org/licenses/mit-license.php
3+ Author Alexander Akait @alexander-akait
4+ */
5+
6+ "use strict" ;
7+
8+ /**
9+ * @param {number } a a
10+ * @param {number } b b
11+ * @returns {number } result
12+ */
13+ function sum ( a , b ) {
14+ return a + b ;
15+ }
16+
17+ sum ( 1 , 2 ) ;
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " webpack-package" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " Test"
5+ }
You can’t perform that action at this time.
0 commit comments