1 | #!/usr/bin/env node
|
2 | "use strict";exports.__esModule=true;exports.nextLint=void 0;var _fs=require("fs");var _index=_interopRequireDefault(require("next/dist/compiled/arg/index.js"));var _path=require("path");var _chalk=_interopRequireDefault(require("chalk"));var _constants=require("../lib/constants");var _runLintCheck=require("../lib/eslint/runLintCheck");var _utils=require("../server/lib/utils");var _storage=require("../telemetry/storage");var _config=_interopRequireDefault(require("../next-server/server/config"));var _constants2=require("../next-server/lib/constants");var _events=require("../telemetry/events");var _compileError=require("../lib/compile-error");function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}const eslintOptions=args=>{var _args$Ext,_args$Rulesdir,_args$Fix,_args$FixType,_args$Cache;return{overrideConfigFile:args['--config']||null,extensions:(_args$Ext=args['--ext'])!=null?_args$Ext:['.js','.jsx','.ts','.tsx'],resolvePluginsRelativeTo:args['--resolve-plugins-relative-to']||null,rulePaths:(_args$Rulesdir=args['--rulesdir'])!=null?_args$Rulesdir:[],fix:(_args$Fix=args['--fix'])!=null?_args$Fix:false,fixTypes:(_args$FixType=args['--fix-type'])!=null?_args$FixType:null,ignorePath:args['--ignore-path']||null,ignore:!Boolean(args['--no-ignore']),allowInlineConfig:!Boolean(args['--no-inline-config']),reportUnusedDisableDirectives:args['--report-unused-disable-directives']||null,cache:(_args$Cache=args['--cache'])!=null?_args$Cache:false,cacheLocation:args['--cache-location']||'.eslintcache',errorOnUnmatchedPattern:!Boolean(args['--no-error-on-unmatched-pattern'])};};const nextLint=argv=>{const validArgs={
|
3 | '--help':Boolean,'--base-dir':String,'--dir':[String],
|
4 | '-h':'--help','-b':'--base-dir','-d':'--dir'};const validEslintArgs={
|
5 | '--config':String,'--ext':[String],'--resolve-plugins-relative-to':String,'--rulesdir':[String],'--fix':Boolean,'--fix-type':[String],'--ignore-path':String,'--no-ignore':Boolean,'--quiet':Boolean,'--no-inline-config':Boolean,'--report-unused-disable-directives':String,'--cache':Boolean,'--cache-location':String,'--no-error-on-unmatched-pattern':Boolean,
|
6 | '-c':'--config'};let args;try{args=(0,_index.default)({...validArgs,...validEslintArgs},{argv});}catch(error){if(error.code==='ARG_UNKNOWN_OPTION'){return(0,_utils.printAndExit)(error.message,1);}throw error;}if(args['--help']){(0,_utils.printAndExit)(`
|
7 | Description
|
8 | Run ESLint on every file in specified directories.
|
9 | If not configured, ESLint will be set up for the first time.
|
10 |
|
11 | Usage
|
12 | $ next lint <baseDir> [options]
|
13 |
|
14 | <baseDir> represents the directory of the Next.js application.
|
15 | If no directory is provided, the current directory will be used.
|
16 |
|
17 | Options
|
18 | Basic configuration:
|
19 | -h, --help List this help
|
20 | -d, --dir Array Set directory, or directories, to run ESLint - default: 'pages', 'components', and 'lib'
|
21 | -c, --config path::String Use this configuration file, overriding all other config options
|
22 | --ext [String] Specify JavaScript file extensions - default: .js, .jsx, .ts, .tsx
|
23 | --resolve-plugins-relative-to path::String A folder where plugins should be resolved from, CWD by default
|
24 |
|
25 | Specifying rules:
|
26 | --rulesdir [path::String] Use additional rules from this directory
|
27 |
|
28 | Fixing problems:
|
29 | --fix Automatically fix problems
|
30 | --fix-type Array Specify the types of fixes to apply (problem, suggestion, layout)
|
31 |
|
32 | Ignoring files:
|
33 | --ignore-path path::String Specify path of ignore file
|
34 | --no-ignore Disable use of ignore files and patterns
|
35 |
|
36 | Handling warnings:
|
37 | --quiet Report errors only - default: false
|
38 |
|
39 | Inline configuration comments:
|
40 | --no-inline-config Prevent comments from changing config or rules
|
41 | --report-unused-disable-directives Adds reported errors for unused eslint-disable directives ("error" | "warn" | "off")
|
42 |
|
43 | Caching:
|
44 | --cache Only check changed files - default: false
|
45 | --cache-location path::String Path to the cache file or directory - default: .eslintcache
|
46 |
|
47 | Miscellaneous:
|
48 | --no-error-on-unmatched-pattern Prevent errors when pattern is unmatched - default: false
|
49 | `,0);}const baseDir=(0,_path.resolve)(args._[0]||'.');
|
50 | if(!(0,_fs.existsSync)(baseDir)){(0,_utils.printAndExit)(`> No such directory exists as the project root: ${baseDir}`);}const dirs=args['--dir'];const lintDirs=(dirs!=null?dirs:_constants.ESLINT_DEFAULT_DIRS).reduce((res,d)=>{const currDir=(0,_path.join)(baseDir,d);if(!(0,_fs.existsSync)(currDir))return res;res.push(currDir);return res;},[]);const reportErrorsOnly=Boolean(args['--quiet']);(0,_runLintCheck.runLintCheck)(baseDir,lintDirs,false,eslintOptions(args),reportErrorsOnly).then(async lintResults=>{const lintOutput=typeof lintResults==='string'?lintResults:lintResults==null?void 0:lintResults.output;if(typeof lintResults!=='string'&&lintResults!=null&&lintResults.eventInfo){const conf=await(0,_config.default)(_constants2.PHASE_PRODUCTION_BUILD,baseDir);const telemetry=new _storage.Telemetry({distDir:(0,_path.join)(baseDir,conf.distDir)});telemetry.record((0,_events.eventLintCheckCompleted)({...lintResults.eventInfo,buildLint:false}));await telemetry.flush();}if(typeof lintResults!=='string'&&lintResults!=null&&lintResults.isError&&lintOutput){throw new _compileError.CompileError(lintOutput);}if(lintOutput){console.log(lintOutput);}else{console.log(_chalk.default.green('✔ No ESLint warnings or errors'));}}).catch(err=>{(0,_utils.printAndExit)(err.message);});};exports.nextLint=nextLint;
|
51 |
|
\ | No newline at end of file |