中微子超光速

    技术2022-07-11  131

    中微子超光速

    Last week my friend Eli Perelman shared Modern JavaScript Apps with Neutrino, an awesome new Node.js tool for creating amazing apps with minimal fuss.  No need to learn webpack, scour babel plugins, or search for what exactly is required to get a React.js app up and running -- just install Neutrino and go!  I've been super impressed with Eli's work and the ease of development for customization.

    上周,我的朋友Eli Perelman 与Neutrino共享了Modern JavaScript Apps,Neutrono是一个很棒的新Node.js工具,用于以最小的麻烦创建出色的应用程序。 无需学习webpack,搜索babel插件或搜索启动和运行React.js应用程序所需的确切内容-只需安装Neutrino即可! Eli的工作和定制开发的简易性给我留下了深刻的印象。

    One important customization for me was the ability to modify default linting rules and running the lint routine from command line when I wanted to.  Neutrino does provide a default ESLint rule set, and does lint while you modify your code, but testing if linting passes within CI is also important.  Let's look at how we can create custom linting rules with our own custom preset!

    对我来说,一项重要的自定义功能是能够修改默认的掉毛规则并在需要时从命令行运行lint例程。 Neutrino确实提供了默认的ESLint规则集,并且在您修改代码时也提供了lint,但是测试是否在CI中通过掉毛也很重要。 让我们看看如何使用我们自己的自定义预设创建自定义棉绒规则!

    步骤1:建立预设 (Step 1:  Creating a Preset)

    Presets allow you to customize elements of your Neutrino app, like ESLint rules, Babel plugins, pathing, and other app-wide global configuration.  Let me first show you the code for custom linting rules and then I'll explain what's going on:

    预设允许您自定义Neutrino应用程序的元素,例如ESLint规则,Babel插件,路径以及其他应用程序范围的全局配置。 首先让我向您展示自定义棉绒规则的代码,然后再说明发生了什么:

    const lint = require('neutrino-lint-base'); const merge = require('deepmerge'); module.exports = neutrino => { // Implement custom linting lint(neutrino); neutrino.config.module .rule('lint') .loader('eslint', props => merge(props, { options: { globals: ['describe', 'expect', 'jest', 'test', 'document', 'window', 'fetch'], rules: { // Don't require () for single argument arrow functions 'arrow-parens': 'off', // Don't require trailing commas 'comma-dangle': 'off', // Don't require file extensions on imports 'import/extensions': 'off', // Don't mark as unresolved without extensions 'import/no-unresolved': 'off', // Don't let ESLint tell us how to use whitespace for imports 'padded-blocks': 'off', // Hold off on propTypes for now 'react/prop-types': 'off' }, baseConfig: { extends: ['airbnb-base', 'plugin:react/recommended'] } } })) };

    Sending neutrino into lint preps the Neutrino app for linting.  Next we use merge to deep merge the custom linting config with our own rules:

    将neutrino发送到lint中将准备使用中微子应用程序。 接下来,我们使用merge将定制的linting配置与我们自己的规则进行深度合并:

    Extend airbnb-base linting rules with are a very popular set of ES6 guidelines

    通过一系列非常流行的ES6准则扩展airbnb-base规则

    Extend recommended React.js linting guidelines

    扩展推荐的React.js linting指南 Specify which globals we'll allow when linting

    指定掉毛时允许使用的全局变量 Set values for very specific ESLint rules we do or don't want to enforce

    为我们要执行或不想执行的非常特定的ESLint规则设置值

    Of course the rules I've customized above are completely my preference; you don't need to extend any existing ESLint libraries (like I did with airbnb and React) and you can enforce whichever rules you'd like.

    当然,我上面自定义的规则完全是我的偏爱。 您不需要扩展任何现有的ESLint库(就像我对airbnb和React所做的那样),并且可以执行所需的任何规则。

    步骤2: .eslintrc.js (Step 2:  .eslintrc.js)

    If you want to run linting from the command line at any time (in the case of CI or a post-commit hook, for example), you will need to create a .eslintrc.js file to kick off the linting:

    如果您想随时从命令行运行linting(例如,对于CI或后提交挂钩),则需要创建.eslintrc.js文件以启动.eslintrc.js :

    const Neutrino = require('neutrino'); const pkg = require('./package.json'); const api = new Neutrino(pkg.config.presets); module.exports = api.custom.eslintrc();

    .eslintrc.js creates a Neutrino instance with presets defined in package.json (we'll get to that in the next section) and exposes a eslintrc() function that runs the lint routine.

    .eslintrc.js使用在package.json定义的预设创建一个Neutrino实例(我们将在下一部分中进行介绍),并公开运行lint例程的eslintrc()函数。

    步骤3:修改package.json (Step 3:  Modify package.json)

    With the preset created with your custom linting rules in mind, a few changes to package.json must be made.  The first is adding this custom preset file to the config.presets array:

    牢记您的自定义插入规则创建的预设,必须对package.json进行一些更改。 首先是将此自定义预设文件添加到config.presets数组中:

    "config": { "presets": [ "neutrino-preset-react", "conduit-preset.js" ] },

    Next we'll need to add Neutrino's airbnb preset to our dependency list:

    接下来,我们需要将Neutrino的airbnb预设添加到我们的依赖项列表中:

    yarn add neutrino-preset-airbnb-base -dev

    Lastly we'll add a lint key to scripts so that we can run linting from command line:

    最后,我们将一个lint键添加到scripts以便我们可以从命令行运行linting:

    "scripts": { "lint": "./node_modules/eslint/bin/eslint.js --ext .js,.jsx src/ test/", }

    Now we can run the following from command line:

    现在我们可以从命令行运行以下命令:

    yarn lint

    Also note that the custom linting rule are applied to both the manual lint command as well as during webpack's live reload and linting routine!

    还要注意,自定义的lint规则既适用于手动lint命令,也适用于webpack的实时重新加载和掉毛例程!

    I love Neutrino because it requires minimal configuration to get up and running but custom configuration is easy when you need to.  Keep an eye on Neutrino moving forward because development is shipping quickly and the community is rallying behind this amazing project!

    我喜欢Neutrino,因为它需要最少的配置来启动和运行,但是自定义配置在需要时很容易。 密切注意Neutrino的前进,因为发展Swift,社区正在为这个令人惊叹的项目提供支持!

    翻译自: https://davidwalsh.name/neutrino-linting

    中微子超光速

    相关资源:论文研究 - 激光辅助产生和检测非核低能中微子-抗中微子束
    Processed: 0.009, SQL: 9